uc_quote.rules.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Rules hooks for uc_quote.module.
  5. */
  6. /**
  7. * Implements hook_rules_condition_info().
  8. */
  9. function uc_quote_rules_condition_info() {
  10. return array(
  11. 'uc_quote_condition_order_shipping_method' => array(
  12. 'label' => t("Order has a shipping quote from a particular method"),
  13. 'group' => t('Order: Shipping Quote'),
  14. 'base' => 'uc_quote_condition_order_shipping_method',
  15. 'parameter' => array(
  16. 'order' => array('type' => 'uc_order', 'label' => t('Order')),
  17. 'method' => array('type' => 'text', 'label' => t('Shipping method'), 'options list' => 'uc_quote_condition_order_shipping_method_options'),
  18. ),
  19. ),
  20. );
  21. }
  22. /**
  23. * Checks an order's shipping method.
  24. */
  25. function uc_quote_condition_order_shipping_method($order, $method) {
  26. // Check the easy way first.
  27. if (!empty($order->quote)) {
  28. return $order->quote['method'] == $method;
  29. }
  30. // Otherwise, look harder.
  31. if (!empty($order->line_items)) {
  32. $methods = module_invoke_all('uc_shipping_method');
  33. $accessorials = $methods[$method]['quote']['accessorials'];
  34. foreach ($order->line_items as $line_item) {
  35. if ($line_item['type'] == 'shipping' && in_array($line_item['title'], $accessorials)) {
  36. return TRUE;
  37. }
  38. }
  39. }
  40. return FALSE;
  41. }
  42. /**
  43. * Options callback.
  44. *
  45. * @see uc_quote_condition_order_shipping_method()
  46. */
  47. function uc_quote_condition_order_shipping_method_options() {
  48. $methods = module_invoke_all('uc_shipping_method');
  49. $enabled = variable_get('uc_quote_enabled', array());
  50. $options = array();
  51. foreach ($methods as $id => $method) {
  52. $options[$id] = $method['title'];
  53. if (!isset($enabled[$id]) || !$enabled[$id]) {
  54. $options[$id] .= ' ' . t('(disabled)');
  55. }
  56. }
  57. return $options;
  58. }