uc_usps.rules_defaults.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @file
  4. * Rules configurations for uc_usps module.
  5. */
  6. /**
  7. * Implements hook_default_rules_configuration_alter().
  8. */
  9. function uc_usps_default_rules_configuration_alter(&$configs) {
  10. if (!isset($configs['get_quote_from_usps'])) {
  11. return;
  12. }
  13. // Domestic areas include U.S., American Samoa, Guam, Puerto Rico,
  14. // and the US Virgin Islands.
  15. $countries = array(
  16. 16 => t('American Samoa'),
  17. 316 => t('Guam'),
  18. 630 => t('Puerto Rico'),
  19. 840 => t('United States'),
  20. 850 => t('Virgin Islands (US)'),
  21. );
  22. $domestic = rules_or();
  23. $domestic->label = t('Order delivers to one of');
  24. $domestic_env = clone $domestic;
  25. $foreign = rules_or();
  26. $foreign->negate();
  27. $foreign->label = t('NOT Order delivers to one of');
  28. $foreign_env = clone $foreign;
  29. foreach ($countries as $country => $name) {
  30. $condition = rules_condition('data_is', array('data:select' => 'order:delivery-address:country', 'value' => $country));
  31. $condition->label = $name;
  32. $domestic->condition(clone $condition);
  33. $domestic_env->condition(clone $condition);
  34. $foreign->condition(clone $condition);
  35. $foreign_env->condition($condition);
  36. }
  37. $configs['get_quote_from_usps']->condition($domestic);
  38. $configs['get_quote_from_usps_env']->condition($domestic_env);
  39. $configs['get_quote_from_usps_intl']->condition($foreign);
  40. $configs['get_quote_from_usps_intl_env']->condition($foreign_env);
  41. }