function _commerce_webform_cart_validate in Commerce Webform 7.2
Same name and namespace in other branches
- 8 commerce_webform.module \_commerce_webform_cart_validate()
- 7 commerce_webform.module \_commerce_webform_cart_validate()
Commerce cart validation function. If there are commerce_webform elements in the cart, check if any have a variable quantity but are required and remove all webform items if the quantity was set to 0.
1 string reference to '_commerce_webform_cart_validate'
- commerce_webform_form_views_form_commerce_cart_form_default_alter in ./
commerce_webform.module - Implements hook_form_FORM_ID_alter(). Modify the cart modification form.
File
- ./
commerce_webform.module, line 674 - Commerce Webform module file
Code
function _commerce_webform_cart_validate(&$form, &$form_state) {
foreach (element_children($form['edit_quantity']) as $id) {
if ($form_state['values']['edit_quantity'][$id] < 1) {
// If the quantity has been reduced to 0,
// check if this is a required commerce_webform line item.
$line_item_id = $form['edit_quantity'][$id]['#line_item_id'];
$line_item = commerce_line_item_load($line_item_id);
if ($line_item->type == 'commerce_webform' && $line_item->data['commerce_webform']['required']) {
$sid = entity_metadata_wrapper('commerce_line_item', $line_item)->commerce_webform_sid
->value();
if ($sid > 0) {
_commerce_webform_remove_line_items_from_cart_form_by_sid($form, $form_state, $sid);
}
}
}
}
}