You are here

function commerce_coupon_line_item_configuration in Commerce Coupon 7

Ensures the coupon line item type contains a coupon reference field.

This function is called by the line item module when it is enabled or this module is enabled. It invokes this function using the configuration_callback as specified above.

2 calls to commerce_coupon_line_item_configuration()
commerce_coupon_update_7002 in ./commerce_coupon.install
Implements hook_update_N(). Remove coupon type id field and update coupon reference field.
commerce_coupon_update_7004 in ./commerce_coupon.install
Implements hook_update_N(). Embrace EntityReference module.

File

./commerce_coupon.module, line 962
Coupon System for Drupal Commerce.

Code

function commerce_coupon_line_item_configuration() {
  $entity_type = 'commerce_line_item';
  $bundle = 'commerce_coupon';

  // Look for or add the specified coupon code
  $field_name = 'commerce_coupon_reference';
  $field = field_info_field($field_name);
  $instance = field_info_instance($entity_type, $field_name, $bundle);
  if (empty($field)) {
    $field = commerce_coupon_reference_field($field_name, 1);
    field_create_field($field);
  }
  if (empty($instance)) {
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'bundle' => $bundle,
      'label' => t('Coupon'),
      'required' => FALSE,
      'settings' => array(),
      'display' => array(),
      'widget' => array(
        'type' => 'entityreference_autocomplete',
        'module' => 'entityreference',
      ),
    );
    field_create_instance($instance);
  }
}