You are here

function _commerce_coupon_install_inline_conditions_field in Commerce Coupon 7.2

Install inline conditions field. Only called by submodules.

5 calls to _commerce_coupon_install_inline_conditions_field()
commerce_coupon_date_flush_caches in modules/date/commerce_coupon_date.module
Implements hook_flush_caches().
commerce_coupon_date_install in modules/date/commerce_coupon_date.install
commerce_coupon_update_7200 in ./commerce_coupon.install
Upgrade a Coupons 1.x site to 2.x. MAKE A BACKUP BEFORE DOING THIS.
commerce_coupon_usage_flush_caches in modules/usage/commerce_coupon_usage.module
Implements hook_flush_caches().
commerce_coupon_usage_install in modules/usage/commerce_coupon_usage.install
Implements hook_install().

File

./commerce_coupon.module, line 2112
Provides coupon functionality for Drupal Commerce.

Code

function _commerce_coupon_install_inline_conditions_field() {
  field_info_cache_clear();
  $fields = field_info_fields();
  $instances = field_info_instances();
  if (empty($fields['commerce_coupon_conditions'])) {

    // Create coupon conditions field.
    $field = array(
      'entity_types' => array(
        'commerce_coupon',
      ),
      'field_name' => 'commerce_coupon_conditions',
      'type' => 'inline_conditions',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    );
    field_create_field($field);
  }

  // Add coupon conditions field to discount coupons.
  foreach (commerce_coupon_get_types(TRUE) as $machine_name => $type) {
    if (empty($instances['commerce_coupon'][$machine_name]['commerce_coupon_conditions'])) {
      $instance = array(
        'field_name' => 'commerce_coupon_conditions',
        'entity_type' => 'commerce_coupon',
        'settings' => array(
          'entity_type' => 'commerce_coupon',
        ),
        'bundle' => $machine_name,
        'label' => t('Conditions'),
        'widget' => array(
          'type' => 'inline_conditions',
          'weight' => 10,
        ),
      );
      field_create_instance($instance);
    }
  }
}