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

Contents of /contributions/modules/ubercart/uc_order/uc_order.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:02 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 * order related entity, conditions, events, and actions work.
8 */
9
10
11 /******************************************************************************
12 * Conditional Actions Hooks *
13 ******************************************************************************/
14
15 /**
16 * Implementation of hook_ca_entity().
17 */
18 function uc_order_ca_entity() {
19 $entities['uc_order'] = array(
20 '#title' => t('Ubercart order object'),
21 '#type' => 'object',
22 '#load' => 'uc_order_load',
23 '#save' => 'uc_order_save',
24 );
25
26 return $entities;
27 }
28
29 /**
30 * Implementation of hook_ca_trigger().
31 */
32 function uc_order_ca_trigger() {
33 $triggers['uc_order_status_update'] = array(
34 '#title' => t('Order status gets updated'),
35 '#category' => t('Order'),
36 '#arguments' => array(
37 'order' => array(
38 '#entity' => 'uc_order',
39 '#title' => t('Order'),
40 ),
41 'updated_order' => array(
42 '#entity' => 'uc_order',
43 '#label' => t('Updated order'),
44 ),
45 ),
46 );
47
48 return $triggers;
49 }
50
51 /**
52 * Implementation of hook_ca_condition().
53 */
54 function uc_order_ca_condition() {
55 $order_arg = array(
56 '#entity' => 'uc_order',
57 );
58
59 $conditions['uc_order_status_condition'] = array(
60 '#title' => t('Check the order status'),
61 '#category' => t('Order'),
62 '#callback' => 'uc_order_condition_check_order_status',
63 '#arguments' => array(
64 'order' => $order_arg,
65 ),
66 );
67
68 $conditions['uc_order_condition_total'] = array(
69 '#title' => t('Check the order total'),
70 '#category' => t('Order'),
71 '#callback' => 'uc_order_condition_total',
72 '#arguments' => array(
73 'order' => $order_arg,
74 ),
75 );
76
77 $conditions['uc_order_condition_delivery_postal_code'] = array(
78 '#title' => t("Check an order's shipping postal code"),
79 '#category' => t('Order: Shipping address'),
80 '#description' => t('Returns TRUE if the shipping postal code is in the specified area.'),
81 '#callback' => 'uc_order_condition_delivery_postal_code',
82 '#arguments' => array(
83 'order' => $order_arg
84 ),
85 );
86 $conditions['uc_order_condition_delivery_zone'] = array(
87 '#title' => t("Check an order's shipping zone"),
88 '#category' => t('Order: Shipping address'),
89 '#description' => t('Returns TRUE if the shipping zone is in the specified list.'),
90 '#callback' => 'uc_order_condition_delivery_zone',
91 '#arguments' => array(
92 'order' => $order_arg,
93 ),
94 );
95 $conditions['uc_order_condition_delivery_country'] = array(
96 '#title' => t("Check an order's shipping country"),
97 '#category' => t('Order: Shipping address'),
98 '#description' => t('Returns TRUE if the shipping country is in the specified list.'),
99 '#callback' => 'uc_order_condition_delivery_country',
100 '#arguments' => array(
101 'order' => $order_arg,
102 ),
103 );
104 $conditions['uc_order_condition_billing_postal_code'] = array(
105 '#title' => t("Check an order's billing postal code"),
106 '#category' => t('Order: Billing address'),
107 '#description' => t('Returns TRUE if the billing postal code is in the specified area.'),
108 '#callback' => 'uc_order_condition_billing_postal_code',
109 '#arguments' => array(
110 'order' => $order_arg,
111 ),
112 );
113 $conditions['uc_order_condition_billing_zone'] = array(
114 '#title' => t("Check an order's billing zone"),
115 '#category' => t('Order: Billing address'),
116 '#description' => t('Returns TRUE if the billing zone is in the specified list.'),
117 '#callback' => 'uc_order_condition_billing_zone',
118 '#arguments' => array(
119 'order' => $order_arg,
120 ),
121 );
122 $conditions['uc_order_condition_billing_country'] = array(
123 '#title' => t("Check an order's billing country"),
124 '#category' => t('Order: Billing address'),
125 '#description' => t('Returns TRUE if the billing country is in the specified list.'),
126 '#callback' => 'uc_order_condition_billing_country',
127 '#arguments' => array(
128 'order' => $order_arg,
129 ),
130 );
131 $conditions['uc_order_condition_has_products'] = array(
132 '#title' => t("Check an order's products"),
133 '#category' => t('Order: Product'),
134 '#description' => t('Returns TRUE if the order has any, all, or only the products in the list.'),
135 '#callback' => 'uc_order_condition_has_products',
136 '#arguments' => array(
137 'order' => $order_arg,
138 ),
139 );
140 $conditions['uc_order_condition_count_products'] = array(
141 '#title' => t("Check an order's number of products"),
142 '#category' => t('Order: Product'),
143 '#description' => t('Determines if the order has the specified number of products, possibly of a certain type.'),
144 '#callback' => 'uc_order_condition_count_products',
145 '#arguments' => array(
146 'order' => $order_arg,
147 ),
148 );
149 $conditions['uc_order_condition_products_weight'] = array(
150 '#title' => t("Check an order's total weight"),
151 '#category' => t('Order: Product'),
152 '#description' => t('Determines if the order has the specified weight, possibly counting only a certain type of product.'),
153 '#callback' => 'uc_order_condition_products_weight',
154 '#arguments' => array(
155 'order' => $order_arg,
156 ),
157 );
158 $conditions['uc_order_condition_is_shippable'] = array(
159 '#title' => t('Check if an order can be shipped'),
160 '#category' => t('Order'),
161 '#description' => t('Returns TRUE if the order has any shippable products.'),
162 '#callback' => 'uc_order_condition_is_shippable',
163 '#arguments' => array(
164 'order' => $order_arg,
165 ),
166 );
167
168 return $conditions;
169 }
170
171 /**
172 * Implementation of hook_ca_action().
173 */
174 function uc_order_ca_action() {
175 $order_arg = array(
176 '#entity' => 'uc_order',
177 '#title' => t('Order'),
178 );
179
180 $actions['uc_order_update_status'] = array(
181 '#title' => t('Update the order status'),
182 '#category' => t('Order'),
183 '#callback' => 'uc_order_action_update_status',
184 '#arguments' => array(
185 'order' => $order_arg,
186 ),
187 );
188 $actions['uc_order_action_add_comment'] = array(
189 '#title' => t('Add a comment to the order'),
190 '#category' => t('Order'),
191 '#callback' => 'uc_order_action_add_comment',
192 '#arguments' => array(
193 'order' => $order_arg,
194 ),
195 );
196
197 return $actions;
198 }
199
200
201 /******************************************************************************
202 * Condition Callbacks and Forms *
203 ******************************************************************************/
204
205 // Check the current order status.
206 function uc_order_condition_check_order_status($order, $settings) {
207 // Return TRUE if the order status matches.
208 $status = db_result(db_query("SELECT order_status FROM {uc_orders} WHERE order_id = %d", $order->order_id));
209 return $status == $settings['order_status'];
210 }
211
212 function uc_order_condition_check_order_status_form($form_state, $settings = array()) {
213 foreach (uc_order_status_list('general') as $status) {
214 $options[$status['id']] = $status['title'];
215 }
216 foreach (uc_order_status_list('specific') as $status) {
217 $options[$status['id']] = $status['title'];
218 }
219 $form['order_status'] = array(
220 '#type' => 'select',
221 '#title' => t('Order status'),
222 '#options' => $options,
223 '#default_value' => $settings['order_status'],
224 );
225
226 return $form;
227 }
228
229 function uc_order_condition_check_order_status_submit($form_id, &$form_state) {
230 return array('order_status' => $form_state['values']['order_status']);
231 }
232
233 // Check the current order balance.
234 function uc_order_condition_total($order, $settings) {
235 switch ($settings['order_total_comparison']) {
236 case 'less':
237 return $order->order_total < $settings['order_total_value'];
238 case 'less_equal':
239 return $order->order_total <= $settings['order_total_value'];
240 case 'equal':
241 return $order->order_total == $settings['order_total_value'];
242 case 'greater_equal':
243 return $order->order_total >= $settings['order_total_value'];
244 case 'greater':
245 return $order->order_total > $settings['order_total_value'];
246 }
247 }
248
249 function uc_order_condition_total_form($form_state, $settings = array()) {
250 $form['order_total_value'] = array(
251 '#type' => 'textfield',
252 '#title' => t('Order total value'),
253 '#description' => t('Specify a value to compare the order total against.'),
254 '#default_value' => $settings['order_total_value'],
255 '#size' => 16,
256 '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
257 '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
258 );
259
260 $options = array(
261 'less' => t('Total is less than specified value.'),
262 'less_equal' => t('Total is less than or equal to specified value.'),
263 'equal' => t('Total is equal to specified value.'),
264 'greater_equal' => t('Total is greater than or equal to specified value.'),
265 'greater' => t('Total is greater than specified value.'),
266 );
267 $form['order_total_comparison'] = array(
268 '#type' => 'radios',
269 '#title' => t('Order total comparison type'),
270 '#options' => $options,
271 '#default_value' => isset($settings['order_total_comparison']) ? $settings['order_total_comparison'] : 'greater_equal',
272 );
273
274 return $form;
275 }
276
277 function uc_order_condition_total_submit($form_id, &$form_state) {
278 $array = array(
279 'order_total_comparison' => $form_state['values']['order_total_comparison'],
280 'order_total_value' => $form_state['values']['order_total_value'],
281 );
282 return $array;
283 }
284
285 // Check an order's delivery postal code.
286 function uc_order_condition_delivery_postal_code($order, $settings) {
287 // Trim the wildcard off the pattern.
288 $pattern = rtrim($settings['pattern'], '*');
289
290 // Return TRUE if the delivery postal code begins with the pattern.
291 return strpos($order->delivery_postal_code, $pattern) === 0;
292 }
293
294 function uc_order_condition_delivery_postal_code_form($form_state, $settings = array()) {
295 $form['pattern'] = array(
296 '#type' => 'textfield',
297 '#title' => uc_get_field_name('postal_code'),
298 '#default_value' => $settings['pattern'],
299 '#description' => t('Specify a postal code or postal code pattern. Use "*" as a wild card to specify a range of postal codes.<br /><b>Example:</b> In the US, 402* represents all areas from 40200 to 40299.'),
300 '#size' => 15,
301 '#required' => TRUE,
302 );
303
304 return $form;
305 }
306
307 function uc_order_condition_delivery_postal_code_submit($form_id, &$form_state) {
308 return array('pattern' => $form_state['values']['pattern']);
309 }
310
311 // Check an order's delivery zone.
312 function uc_order_condition_delivery_zone($order, $settings) {
313 return in_array($order->delivery_zone, $settings['zones']);
314 }
315
316 function uc_order_condition_delivery_zone_form($form_state, $settings = array()) {
317 $result = db_query("SELECT z.*, c.country_name FROM {uc_zones} AS z LEFT JOIN {uc_countries} AS c ON z.zone_country_id = c.country_id ORDER BY c.country_name, z.zone_name");
318 while ($zone = db_fetch_object($result)) {
319 $options[$zone->country_name][$zone->zone_id] = $zone->zone_name;
320 }
321
322 $form['zones'] = array(
323 '#type' => 'select',
324 '#title' => uc_get_field_name('zone'),
325 '#options' => $options,
326 '#default_value' => $settings['zones'],
327 '#multiple' => TRUE,
328 '#required' => TRUE,
329 );
330
331 return $form;
332 }
333
334 function uc_order_condition_delivery_zone_submit($form_id, &$form_state) {
335 return array('zones' => $form_state['values']['zones']);
336 }
337
338 // Check an order's delivery country.
339 function uc_order_condition_delivery_country($order, $settings) {
340 return in_array($order->delivery_country, $settings['countries']);
341 }
342
343 function uc_order_condition_delivery_country_form($form_state, $settings = array()) {
344 $form['countries'] = uc_country_select(uc_get_field_name('country'));
345 $form['countries']['#default_value'] = $settings['countries'];
346 $form['countries']['#multiple'] = TRUE;
347 $form['countries']['#required'] = TRUE;
348
349 return $form;
350 }
351
352 function uc_order_condition_delivery_country_submit($form_id, &$form_state) {
353 return array('countries' => $form_state['values']['countries']);
354 }
355
356 // Check an order's billing postal code.
357 function uc_order_condition_billing_postal_code($order, $settings) {
358 // Trim the wildcard off the pattern.
359 $pattern = rtrim($settings['pattern'], '*');
360
361 // Return TRUE if the delivery postal code begins with the pattern.
362 return strpos($order->billing_postal_code, $pattern) === 0;
363 }
364
365 function uc_order_condition_billing_postal_code_form($form_state, $settings = array()) {
366 $form['pattern'] = array(
367 '#type' => 'textfield',
368 '#title' => uc_get_field_name('postal_code'),
369 '#default_value' => $settings['pattern'],
370 '#description' => t('Specify a postal code or postal code pattern. Use "*" as a wild card to specify a range of postal codes.<br /><b>Example:</b> In the US, 402* represents all areas from 40200 to 40299.'),
371 '#size' => 15,
372 '#required' => TRUE,
373 );
374
375 return $form;
376 }
377
378 function uc_order_condition_billing_postal_code_submit($form_id, &$form_state) {
379 return array('pattern' => $form_state['values']['pattern']);
380 }
381
382 // Check an order's billing zone.
383 function uc_order_condition_billing_zone($order, $settings) {
384 return in_array($order->billing_zone, $settings['zones']);
385 }
386
387 function uc_order_condition_billing_zone_form($form_state, $settings = array()) {
388 $result = db_query("SELECT z.*, c.country_name FROM {uc_zones} AS z LEFT JOIN {uc_countries} AS c ON z.zone_country_id = c.country_id ORDER BY c.country_name, z.zone_name");
389 while ($zone = db_fetch_object($result)) {
390 $options[$zone->country_name][$zone->zone_id] = $zone->zone_name;
391 }
392
393 $form['zones'] = array(
394 '#type' => 'select',
395 '#title' => uc_get_field_name('zone'),
396 '#options' => $options,
397 '#default_value' => $settings['zones'],
398 '#multiple' => TRUE,
399 '#required' => TRUE,
400 );
401
402 return $form;
403 }
404
405 function uc_order_condition_billing_zone_submit($form_id, &$form_state) {
406 return array('zones' => $form_state['values']['zones']);
407 }
408
409 // Check an order's billing country.
410 function uc_order_condition_billing_country($order, $settings) {
411 return in_array($order->billing_country, $settings['countries']);
412 }
413
414 function uc_order_condition_billing_country_form($form_state, $settings = array()) {
415 $form['countries'] = uc_country_select(uc_get_field_name('country'));
416 $form['countries']['#default_value'] = $settings['countries'];
417 $form['countries']['#multiple'] = TRUE;
418 $form['countries']['#required'] = TRUE;
419
420 return $form;
421 }
422
423 function uc_order_condition_billing_country_submit($form_id, &$form_state) {
424 return array('countries' => $form_state['values']['countries']);
425 }
426
427 function uc_order_condition_has_products($order, $settings) {
428 $products = array();
429 foreach ($order->products as $product) {
430 $products[] = $product->nid;
431 }
432 $required = array_intersect($settings['products'], $products);
433 if ($settings['required']) {
434 $required_check = $required == $settings['products'];
435 }
436 else {
437 $required_check = (bool)count($required);
438 }
439 if ($settings['forbidden']) {
440 $forbidden = array_diff($products, $settings['products']);
441 $forbidden_check = (bool)count($forbidden);
442 }
443 else {
444 $forbidden_check = false;
445 }
446 return $required_check && !$forbidden_check;
447 }
448
449 function uc_order_condition_has_products_form($form_state, $settings = array('required' => 0, 'forbidden' => 0)) {
450 $form['required'] = array('#type' => 'radios',
451 '#title' => t('Require selected products'),
452 '#options' => array(
453 0 => t('Order has any of these products.'),
454 1 => t('Order has all of these products.'),
455 ),
456 '#default_value' => $settings['required'],
457 );
458 $form['forbidden'] = array('#type' => 'radios',
459 '#title' => t('Forbid other products'),
460 '#options' => array(
461 0 => t('Order may have other products.'),
462 1 => t('Order has only these products.'),
463 ),
464 '#default_value' => $settings['forbidden'],
465 );
466 $options = array();
467 $result = db_query("SELECT nid, model FROM {uc_products}");
468 while ($product = db_fetch_object($result)) {
469 $options[$product->nid] = $product->model;
470 }
471 $form['products'] = array('#type' => 'select',
472 '#title' => t('Products'),
473 '#options' => $options,
474 '#default_value' => $settings['products'],
475 '#multiple' => true,
476 );
477 return $form;
478 }
479
480 function uc_order_condition_has_products_submit($form_id, &$form_state) {
481 return array(
482 'required' => $form_state['values']['required'],
483 'forbidden' => $form_state['values']['forbidden'],
484 'products' => $form_state['values']['products'],
485 );
486 }
487
488 function uc_order_condition_count_products($order, $settings) {
489 $totals = array('all' => 0);
490 $total = 0;
491 foreach ($order->products as $product) {
492 $totals['all'] += $product->qty;
493 $totals[$product->nid] = $product->qty;
494 }
495 if (in_array('all', $settings['products'])) {
496 $total = $totals['all'];
497 }
498 else {
499 foreach ($settings['products'] as $product) {
500 $total += $totals[$product];
501 }
502 }
503 switch ($settings['product_count_comparison']) {
504 case 'less':
505 return $total < $settings['product_count_value'];
506 case 'less_equal':
507 return $total <= $settings['product_count_value'];
508 case 'equal':
509 return $total == $settings['product_count_value'];
510 case 'greater_equal':
511 return $total >= $settings['product_count_value'];
512 case 'greater':
513 return $total > $settings['product_count_value'];
514 }
515 }
516
517 function uc_order_condition_count_products_form($form_state, $settings = array()) {
518 $options = array('all' => t('<All products>'));
519 $result = db_query("SELECT nid, model FROM {uc_products} ORDER BY model");
520 while ($product = db_fetch_object($result)) {
521 $options[$product->nid] = $product->model;
522 }
523 $form['products'] = array('#type' => 'select',
524 '#title' => t('Products'),
525 '#options' => $options,
526 '#default_value' => $settings['products'],
527 '#description' => check_plain(t('Selecting "<All products>" will override any other selections and returns the total number of products in the order.')),
528 '#multiple' => true,
529 );
530 $form['product_count_value'] = array(
531 '#type' => 'textfield',
532 '#title' => t('Product count value'),
533 '#description' => t('Specify a value to compare the product count against.'),
534 '#default_value' => $settings['product_count_value'],
535 '#size' => 16,
536 );
537
538 $options = array(
539 'less' => t('Total is less than specified value.'),
540 'less_equal' => t('Total is less than or equal to specified value.'),
541 'equal' => t('Total is equal to specified value.'),
542 'greater_equal' => t('Total is greater than or equal to specified value.'),
543 'greater' => t('Total is greater than specified value.'),
544 );
545 $form['product_count_comparison'] = array(
546 '#type' => 'radios',
547 '#title' => t('Product count comparison type'),
548 '#options' => $options,
549 '#default_value' => isset($settings['product_count_comparison']) ? $settings['product_count_comparison'] : 'greater_equal',
550 );
551
552 return $form;
553 }
554
555 function uc_order_condition_count_products_submit($form_id, &$form_state) {
556 return array(
557 'products' => $form_state['values']['products'],
558 'product_count_value' => $form_state['values']['product_count_value'],
559 'product_count_comparison' => $form_state['values']['product_count_comparison'],
560 );
561 }
562
563 function uc_order_condition_products_weight($order, $settings) {
564 $totals = array('all' => 0);
565 $total = 0;
566 foreach ($order->products as $product) {
567 $unit_conversion = uc_weight_conversion($product->weight_units, $settings['weight_units']);
568 $totals['all'] += $product->qty * $product->weight * $unit_conversion;
569 $totals[$product->model] = $product->qty * $product->weight * $unit_conversion;
570 }
571 if (in_array('all', $settings['products'])) {
572 $total = $totals['all'];
573 }
574 else {
575 foreach ($settings['products'] as $product) {
576 $total += $totals[$product];
577 }
578 }
579 switch ($settings['product_weight_comparison']) {
580 case 'less':
581 return $total < $settings['product_weight_value'];
582 case 'less_equal':
583 return $total <= $settings['product_weight_value'];
584 case 'equal':
585 return $total == $settings['product_weight_value'];
586 case 'greater_equal':
587 return $total >= $settings['product_weight_value'];
588 case 'greater':
589 return $total > $settings['product_weight_value'];
590 }
591 }
592
593 function uc_order_condition_products_weight_form($form_state, $settings = array()) {
594 $options = array('all' => t('<All products>'));
595 $result = db_query("SELECT nid, model FROM {uc_products}");
596 while ($product = db_fetch_object($result)) {
597 $options[$product->nid] = $product->model;
598 }
599 $form['products'] = array('#type' => 'select',
600 '#title' => t('Products'),
601 '#options' => $options,
602 '#default_value' => $settings['products'],
603 '#description' => check_plain(t('Selecting "<All products>" will override any other selections and returns the total number of products in the order.')),
604 '#multiple' => true,
605 );
606 $form['weight_units'] = array('#type' => 'select',
607 '#title' => t('Unit of measurement'),
608 '#default_value' => variable_get('uc_weight_unit', 'lb'),
609 '#options' => array(
610 'lb' => t('Pounds'),
611 'kg' => t('Kilograms'),
612 'oz' => t('Ounces'),
613 'g' => t('Grams'),
614 ),
615 );
616 $form['product_weight_value'] = array(
617 '#type' => 'textfield',
618 '#title' => t('Product weight value'),
619 '#description' => t('Specify a value to compare the product weight against.'),
620 '#default_value' => $settings['product_weight_value'],
621 '#size' => 16,
622 );
623
624 $options = array(
625 'less' => t('Total is less than specified value.'),
626 'less_equal' => t('Total is less than or equal to specified value.'),
627 'equal' => t('Total is equal to specified value.'),
628 'greater_equal' => t('Total is greater than or equal to specified value.'),
629 'greater' => t('Total is greater than specified value.'),
630 );
631 $form['product_weight_comparison'] = array(
632 '#type' => 'radios',
633 '#title' => t('Product count comparison type'),
634 '#options' => $options,
635 '#default_value' => isset($settings['product_weight_comparison']) ? $settings['product_weight_comparison'] : 'greater_equal',
636 );
637
638 return $form;
639 }
640
641 function uc_order_condition_products_weight_submit($form_id, &$form_state) {
642 return array(
643 'products' => $form_state['values']['products'],
644 'product_weight_value' => $form_state['values']['product_weight_value'],
645 'product_weight_comparison' => $form_state['values']['product_weight_comparison'],
646 );
647 }
648
649 function uc_order_condition_is_shippable($order, $settings) {
650 return uc_order_is_shippable($order);
651 }
652
653 /******************************************************************************
654 * Action Callbacks and Forms *
655 ******************************************************************************/
656
657 // Update an order's status.
658 function uc_order_action_update_status(&$order, $settings) {
659 if (uc_order_update_status($order->order_id, $settings['order_status'])) {
660 $order->order_status = $settings['order_status'];
661 }
662 }
663
664 function uc_order_action_update_status_form($form_state, $settings = array()) {
665 foreach (uc_order_status_list('general') as $status) {
666 $options[$status['id']] = $status['title'];
667 }
668 foreach (uc_order_status_list('specific') as $status) {
669 $options[$status['id']] = $status['title'];
670 }
671 $form['order_status'] = array(
672 '#type' => 'select',
673 '#title' => t('Order status'),
674 '#options' => $options,
675 '#default_value' => $settings['order_status'],
676 );
677
678 return $form;
679 }
680
681 function uc_order_action_update_status_submit($form_id, &$form_state) {
682 return array('order_status' => $form_state['values']['order_status']);
683 }
684
685 // Add a comment to an order.
686 function uc_order_action_add_comment($order, $settings) {
687 uc_order_comment_save($order->order_id, 0,
688 token_replace_multiple($settings['comment'], array('global' => NULL, 'order' => $order)),
689 $settings['comment_type'] == 'admin' ? 'admin' : 'order',
690 $order->order_status, $settings['comment_type'] == 'notified');
691 }
692
693 function uc_order_action_add_comment_form($form_state, $settings = array()) {
694 $form['comment_type'] = array(
695 '#type' => 'radios',
696 '#title' => t('Select an order comment type'),
697 '#options' => array(
698 'admin' => t('Enter this as an admin comment.'),
699 'order' => t('Enter this as a customer order comment.'),
700 'notified' => t('Enter this as a customer order comment with a notified icon.'),
701 ),
702 '#default_value' => $settings['comment_type'],
703 );
704 $form['comment'] = array(
705 '#type' => 'textarea',
706 '#title' => t('Comment'),
707 '#description' => t('Enter the comment message. Uses <a href="!url">order and global tokens</a>.', array('!url' => url('admin/store/help/tokens'))),
708 '#default_value' => $settings['comment'],
709 );
710
711 return $form;
712 }
713
714 function uc_order_action_add_comment_submit($form_id, &$form_state) {
715 return array('comment_type' => $form_state['values']['comment_type'], 'comment' => $form_state['values']['comment']);
716 }
717

  ViewVC Help
Powered by ViewVC 1.1.2