function commerce_order_has_specific_quantity_products_configure in Commerce Discount 7
Configure callback for commerce_order_has_specific_quantity_products.
Parameters
array $settings: Values for the form element.
Return value
array Return the form element to display.
1 string reference to 'commerce_order_has_specific_quantity_products_configure'
File
- ./
commerce_discount.inline_conditions.inc, line 394 - Provides Inline Conditions integration for the Commerce Discount module.
Code
function commerce_order_has_specific_quantity_products_configure($settings) {
// Ensure we've default settings set.
$settings += array(
'products' => array(),
'operator' => '==',
'quantity' => '',
);
// Get product IDs from $settings.
$default_value = '';
foreach ($settings['products'] as $delta => $product_id) {
$product = commerce_product_load(reset($product_id));
$default_value .= $product->sku;
if ($product_id !== end($settings['products'])) {
$default_value .= ', ';
}
}
$form['products'] = array(
'#type' => 'textfield',
'#title' => t('Products'),
'#title_display' => 'invisible',
'#default_value' => $default_value,
'#required' => TRUE,
'#maxlength' => 4096,
'#autocomplete_path' => 'commerce_product/autocomplete/commerce_product/0/0',
'#element_validate' => array(
'commerce_product_reference_autocomplete_validate',
),
'#attributes' => array(
'placeholder' => array(
t('enter product name'),
),
),
);
module_load_include('inc', 'commerce_discount', 'commerce_discount.rules');
$form['operator'] = array(
'#type' => 'select',
'#title' => t('Quantity'),
'#title_display' => 'before',
'#options' => _commerce_discount_operator_options(),
'#default_value' => !empty($settings['operator']) ? $settings['operator'] : '==',
);
$form['quantity'] = array(
'#type' => 'textfield',
'#title' => t('Quantity'),
'#title_display' => 'invisible',
'#default_value' => !empty($settings['quantity']) ? $settings['quantity'] : '1',
'#size' => 5,
'#required' => TRUE,
'#element_validate' => array(
'element_validate_integer',
),
'#suffix' => '<div class="condition-instructions">' . t("The discount is active if the order's product(s) match the condition above.") . '</div>',
);
return $form;
}