function commerce_coupon_order_configuration in Commerce Coupon 7
Ensures the coupon reference field is present on the default order bundle.
2 calls to commerce_coupon_order_configuration()
- commerce_coupon_enable in ./
commerce_coupon.module - Implements hook_enable().
- commerce_coupon_update_7004 in ./
commerce_coupon.install - Implements hook_update_N(). Embrace EntityReference module.
File
- ./
commerce_coupon.module, line 1005 - Coupon System for Drupal Commerce.
Code
function commerce_coupon_order_configuration($type = 'commerce_order') {
// If a field type we know should exist isn't found, clear the Field cache.
if (!field_info_field_types('entityreference')) {
field_cache_clear();
}
// Look for or add a coupon reference field to the order type.
$field_name = 'commerce_coupon_order_reference';
$field = field_info_field($field_name);
$instance = field_info_instance('commerce_order', $field_name, $type);
if (empty($field)) {
$field = commerce_coupon_reference_field($field_name, FIELD_CARDINALITY_UNLIMITED);
field_create_field($field);
}
if (empty($instance)) {
$instance = array(
'field_name' => $field_name,
'entity_type' => 'commerce_order',
'bundle' => $type,
'label' => t('Coupon'),
'settings' => array(),
'widget' => array(
'type' => 'entityreference_autocomplete',
'module' => 'entityreference',
),
);
// 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' => 'hidden',
);
}
field_create_instance($instance);
}
}