You are here

function commerce_order_address_field_options_list in Commerce Core 7

Options list callback: address fields for the address comparison condition.

1 string reference to 'commerce_order_address_field_options_list'
commerce_order_rules_condition_info in modules/order/commerce_order.rules.inc
Implements hook_rules_condition_info().

File

modules/order/commerce_order.rules.inc, line 164
Rules integration for orders.

Code

function commerce_order_address_field_options_list() {
  $options = array();

  // Retrieve a list of all address fields on customer profile bundles.
  $address_fields = commerce_info_fields('addressfield', 'commerce_customer_profile');

  // Loop over every customer profile reference field on orders.
  foreach (commerce_info_fields('commerce_customer_profile_reference', 'commerce_order') as $field_name => $field) {

    // Retrieve the type of customer profile referenced by this field.
    $type = $field['settings']['profile_type'];

    // Loop over every address field looking for any attached to this bundle.
    foreach ($address_fields as $address_field_name => $address_field) {
      if (in_array($type, $address_field['bundles']['commerce_customer_profile'])) {

        // Add it to the options list.
        $instance = field_info_instance('commerce_customer_profile', 'commerce_customer_address', $type);
        $translated_instance = commerce_i18n_object('field_instance', $instance);
        $options[commerce_customer_profile_type_get_name($type)][$field_name . '|' . $address_field_name] = check_plain($translated_instance['label']);
      }
    }
  }
  if (empty($options)) {
    drupal_set_message(t('No order addresses could be found for comparison.'), 'error');
  }
  return $options;
}