You are here

function commerce_customer_configure_customer_profile_type in Commerce Core 7

Ensures the address field is present on the specified customer profile bundle.

2 calls to commerce_customer_configure_customer_profile_type()
commerce_customer_configure_customer_fields in modules/customer/commerce_customer.module
Configures fields referencing customer profile types defined by enabled modules and configures the fields on those profile types if necessary.
commerce_customer_configure_customer_types in modules/customer/commerce_customer.module
Configures customer profile types defined by enabled modules.

File

modules/customer/commerce_customer.module, line 198
Defines the customer profile entity and API functions to manage customers and interact with them.

Code

function commerce_customer_configure_customer_profile_type($profile_type) {
  if ($profile_type['addressfield']) {

    // Look for or add an address field to the customer profile type.
    $field_name = 'commerce_customer_address';
    commerce_activate_field($field_name);
    field_cache_clear();
    $field = field_info_field($field_name);
    $instance = field_info_instance('commerce_customer_profile', $field_name, $profile_type['type']);
    if (empty($field)) {
      $field = array(
        'field_name' => $field_name,
        'type' => 'addressfield',
        'cardinality' => 1,
        'entity_types' => array(
          'commerce_customer_profile',
        ),
        'translatable' => FALSE,
      );
      $field = field_create_field($field);
    }
    if (empty($instance)) {
      $instance = array(
        'field_name' => $field_name,
        'entity_type' => 'commerce_customer_profile',
        'bundle' => $profile_type['type'],
        'label' => t('Address'),
        'required' => TRUE,
        'widget' => array(
          'type' => 'addressfield_standard',
          'weight' => -10,
          'settings' => array(
            'format_handlers' => array(
              'address',
              'name-oneline',
            ),
          ),
        ),
        'display' => array(),
      );

      // Set the default display formatters for various view modes.
      foreach (array(
        'default',
        'customer',
        'administrator',
      ) as $view_mode) {
        $instance['display'][$view_mode] = array(
          'label' => 'hidden',
          'type' => 'addressfield_default',
          'weight' => -10,
        );
      }
      field_create_instance($instance);
    }
  }
}