function commerce_discount_extra_update_7003 in Commerce Discount Extra 7
Update various settings for the per-quantity discount field instances.
File
- ./
commerce_discount_extra.install, line 512 - Installs necessary fields for extra discounts.
Code
function commerce_discount_extra_update_7003() {
$bundle_names = array(
'per_quantity_fixed',
'per_quantity_percentage',
);
// Update the first set of field instances that exist on both offer types.
foreach ($bundle_names as $bundle_name) {
// Update the trigger quantity instances.
$instance = field_info_instance('commerce_discount_offer', 'commerce_trigger_qty', $bundle_name);
$instance['label'] = t('Buy #');
$instance['description'] = '';
$instance['widget']['weight'] = 0;
field_update_instance($instance);
// Update the trigger product instances.
$instance = field_info_instance('commerce_discount_offer', 'commerce_trigger_products', $bundle_name);
$instance['label'] = t('Of any of these trigger products');
$instance['description'] = t('Leave blank to trigger the discount when <em>any</em> product is purchased.');
$instance['required'] = FALSE;
$instance['widget']['weight'] = 5;
field_update_instance($instance);
// Update the offer quantity instances.
$instance = field_info_instance('commerce_discount_offer', 'commerce_offer_qty', $bundle_name);
$instance['label'] = t('Get up to #');
$instance['description'] = '';
$instance['widget']['weight'] = 10;
field_update_instance($instance);
// Update the offer product instances.
$instance = field_info_instance('commerce_discount_offer', 'commerce_discount_products', $bundle_name);
$instance['label'] = t('Of any of these offer products');
$instance['description'] = '';
$instance['widget']['weight'] = 15;
field_update_instance($instance);
}
// Then update the field instances that exist on just one offer type.
$instance = field_info_instance('commerce_discount_offer', 'commerce_percentage', 'per_quantity_percentage');
$instance['label'] = t('Discounted by');
$instance['description'] = '';
$instance['settings']['suffix'] = t('% as a decimal (e.g. .2 for 20% off)');
$instance['widget']['weight'] = 20;
field_update_instance($instance);
$instance = field_info_instance('commerce_discount_offer', 'commerce_fixed_amount', 'per_quantity_fixed');
$instance['label'] = t('Discounted by');
$instance['description'] = '';
$instance['widget']['weight'] = 20;
field_update_instance($instance);
// Update the second set of field instances that exist on both offer types.
foreach ($bundle_names as $bundle_name) {
// Update the offer limit instances.
$instance = field_info_instance('commerce_discount_offer', 'commerce_offer_limit', $bundle_name);
$instance['label'] = t('On up to #');
$instance['description'] = '';
$instance['settings']['suffix'] = t('different products (leave blank for no limit)');
$instance['widget']['weight'] = 25;
field_update_instance($instance);
// Update the pricing strategy instances.
$instance = field_info_instance('commerce_discount_offer', 'commerce_pricing_strategy', $bundle_name);
$instance['label'] = t('Use the following discounting strategy');
$instance['description'] = '';
$instance['widget']['weight'] = 30;
$instance['widget']['type'] = 'options_buttons';
field_update_instance($instance);
}
// Update the pricing strategy options as well.
$field = field_info_field('commerce_pricing_strategy');
$field['settings']['allowed_values'] = array(
'low_first' => t('Discount the cheapest eligible product(s) first.'),
'high_first' => t('Discount the most expensive eligible product(s) first.'),
);
field_update_field($field);
return st('Per-quantity discount field instances updated.');
}