You are here

function commerce_discount_extra_update_7002 in Commerce Discount Extra 7

Add pricing strategy field to per-qty offers.

File

./commerce_discount_extra.install, line 458
Installs necessary fields for extra discounts.

Code

function commerce_discount_extra_update_7002() {
  field_info_cache_clear();
  $fields = field_info_fields();
  $instances = field_info_instances();

  /*
   * BOGO pricing strategy
   */
  if (empty($fields['commerce_pricing_strategy'])) {
    $field = array(
      'settings' => array(
        'allowed_values' => array(
          'high_first' => 'Highest first',
          'low_first' => 'Lowest first',
        ),
        'allowed_values_function' => '',
        'entity_translation_sync' => FALSE,
      ),
      'field_name' => 'commerce_pricing_strategy',
      'type' => 'list_text',
      'locked' => TRUE,
      'cardinality' => '1',
    );
    field_create_field($field);
  }
  foreach (array(
    'per_quantity_fixed',
    'per_quantity_percentage',
  ) as $type) {
    if (empty($instances['commerce_discount_offer'][$type]['commerce_pricing_strategy'])) {
      $instance = array(
        'label' => 'Pricing strategy',
        'widget' => array(
          'weight' => 15,
          'type' => 'options_select',
          'active' => 1,
          'settings' => array(),
        ),
        'required' => 1,
        'description' => t('Determine whether the offer should discount lowest or highest price products first if there is a choice.'),
        'default_value' => array(
          0 => array(
            'value' => 'low_first',
          ),
        ),
        'field_name' => 'commerce_pricing_strategy',
        'entity_type' => 'commerce_discount_offer',
        'bundle' => $type,
      );
      field_create_instance($instance);
    }
  }
}