function commerce_discount_extra_update_7004 in Commerce Discount Extra 7
Add a field to determine automatic "Add to Cart" behavior for offer products.
File
- ./
commerce_discount_extra.install, line 594 - Installs necessary fields for extra discounts.
Code
function commerce_discount_extra_update_7004() {
field_info_cache_clear();
$fields = field_info_fields();
$instances = field_info_instances();
// Create the automatic "Add to Cart" behavior field if it doesn't exist. This
// field is used to determine when / how offer products should be added to the
// cart when triggering conditions are met.
if (empty($fields['commerce_auto_add_behavior'])) {
$field = array(
'settings' => array(
'allowed_values' => array(
'nothing' => t('Do not automatically add offer products to the cart.'),
'add_first_offer_product' => t('Add the first available offer product to the cart.'),
),
'allowed_values_function' => '',
'entity_translation_sync' => FALSE,
),
'field_name' => 'commerce_auto_add_behavior',
'type' => 'list_text',
'locked' => TRUE,
);
field_create_field($field);
}
foreach (array(
'per_quantity_fixed',
'per_quantity_percentage',
) as $bundle_name) {
if (empty($instances['commerce_discount_offer'][$bundle_name]['commerce_auto_add_behavior'])) {
$instance = array(
'label' => t('When enough trigger products are in the cart but no offer products have been added'),
'widget' => array(
'weight' => 35,
'type' => 'options_buttons',
'active' => TRUE,
'settings' => array(),
),
'required' => TRUE,
'default_value' => array(
0 => array(
'value' => 'nothing',
),
),
'field_name' => 'commerce_auto_add_behavior',
'entity_type' => 'commerce_discount_offer',
'bundle' => $bundle_name,
);
field_create_instance($instance);
}
}
return st('New field added to offer types to automatically add offer products to the cart.');
}