function commerce_order_configure_customer_profile_type in Commerce Core 7
Configure the customer profile reference fields for the specified order type.
Parameters
$customer_profile_type: The machine-name of the customer profile type to reference.
$label: The label to use for the profile type's reference field.
$order_type: The machine-name of the order type to add fields to.
2 calls to commerce_order_configure_customer_profile_type()
- commerce_order_configure_order_fields in modules/
order/ commerce_order.module - Configures the customer profile reference fields attached to the default order type when modules defining customer profile types are enabled after the Order module.
- commerce_order_configure_order_type in modules/
order/ commerce_order.module - Ensures the line item field is present on the default order bundle.
File
- modules/
order/ commerce_order.module, line 218 - Defines the core Commerce order entity and API functions to manage orders and interact with them.
Code
function commerce_order_configure_customer_profile_type($customer_profile_type, $label, $order_type = 'commerce_order') {
// Add the customer profile reference fields for each profile type.
$field_name = 'commerce_customer_' . $customer_profile_type;
// First check to ensure this field doesn't already exist and was just inactive
// because of the profile defining module being disabled previously.
commerce_activate_field($field_name);
field_cache_clear();
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_order', $field_name, $order_type);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'commerce_customer_profile_reference',
'cardinality' => 1,
'entity_types' => array(
'commerce_order',
),
'translatable' => FALSE,
'settings' => array(
'profile_type' => $customer_profile_type,
),
);
$field = field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_order',
'bundle' => $order_type,
'label' => $label,
'widget' => array(
'type' => 'commerce_customer_profile_manager',
'weight' => -5,
),
'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' => 'above',
'type' => 'commerce_customer_profile_reference_display',
'weight' => -5,
);
}
field_create_instance($instance);
variable_set('commerce_customer_profile_' . $customer_profile_type . '_field', $field_name);
}
}