/[drupal]/contributions/modules/ubercart/uc_cart/uc_cart.ca.inc
ViewVC logotype

Contents of /contributions/modules/ubercart/uc_cart/uc_cart.ca.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Thu Jul 10 12:41:00 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: DRUPAL-5--1-2, DRUPAL-5--1-1, HEAD
Branch point for: DRUPAL-6--2
File MIME type: text/x-php
Begin the Ubercart 6.x-2.x branch.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * This file contains the Conditional Actions hooks and functions necessary to make the
7 * cart related entity, conditions, events, and actions work.
8 */
9
10
11 /******************************************************************************
12 * Conditional Actions Hooks *
13 ******************************************************************************/
14
15 /**
16 * Implmentation of hook_ca_condition().
17 */
18 function uc_cart_ca_condition() {
19 $conditions['uc_cart_condition_product_class'] = array(
20 '#title' => t('Order has a product of a particular class'),
21 '#category' => t('Order: Product'),
22 '#callback' => 'uc_cart_condition_product_class',
23 '#arguments' => array(
24 'order' => array(
25 '#entity' => 'uc_order',
26 '#title' => t('Order'),
27 ),
28 ),
29 );
30
31 return $conditions;
32 }
33
34 /**
35 * Implementation of hook_ca_trigger().
36 */
37 function uc_cart_ca_trigger() {
38 $triggers['uc_checkout_complete'] = array(
39 '#title' => t('Customer completes checkout'),
40 '#category' => t('Cart'),
41 '#arguments' => array(
42 'order' => array(
43 '#entity' => 'uc_order',
44 '#title' => t('Order'),
45 ),
46 'account' => array(
47 '#entity' => 'user',
48 '#title' => t('Customer user account'),
49 )
50 ),
51 );
52
53 return $triggers;
54 }
55
56
57 /******************************************************************************
58 * Condition Callbacks and Forms *
59 ******************************************************************************/
60
61 function uc_cart_condition_product_class($order, $settings) {
62 $result = FALSE;
63 $types = array();
64 foreach ($order->products as $product) {
65 // Ignore "blank line" custom products.
66 if ($product->nid) {
67 // Cache product types to avoid extra queries.
68 if (!isset($types[$product->nid])) {
69 if (isset($product->type)) {
70 $types[$product->nid] = $product->type;
71 }
72 else {
73 $types[$product->nid] = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $product->nid));
74 }
75 }
76 if ($types[$product->nid] == $settings['class']) {
77 $result = TRUE;
78 break;
79 }
80 }
81 }
82
83 return $result;
84 }
85
86 function uc_cart_condition_product_class_form($settings = array()) {
87 $options = array();
88 $types = module_invoke_all('node_info');
89 $product_types = module_invoke_all('product_types');
90 foreach ($product_types as $id) {
91 $options[$id] = $types[$id]['name'];
92 }
93 $form['class'] = array('#type' => 'select',
94 '#title' => t('Product class'),
95 '#options' => $options,
96 '#default_value' => $settings['class'],
97 );
98
99 return $form;
100 }
101
102 function uc_cart_condition_product_class_submit($form_id, $form_values) {
103 return array('class' => $form_values['class']);
104 }
105

  ViewVC Help
Powered by ViewVC 1.1.2