You are here

function _commerce_webform_remove_line_items_from_cart_form_by_sid in Commerce Webform 7

Same name and namespace in other branches
  1. 8 commerce_webform.module \_commerce_webform_remove_line_items_from_cart_form_by_sid()
  2. 7.2 commerce_webform.module \_commerce_webform_remove_line_items_from_cart_form_by_sid()

Helper function for use by the cart update form functions. Remove all line items from an order which link to a specific submission.

2 calls to _commerce_webform_remove_line_items_from_cart_form_by_sid()
_commerce_webform_cart_validate in ./commerce_webform.module
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.
_commerce_webform_remove_required_product_from_order in ./commerce_webform.module
Form submission function. Someone has tried to remove a required commerce webform item from an order. Remove all submission products at the same time.

File

./commerce_webform.module, line 656
Commerce Webform module file

Code

function _commerce_webform_remove_line_items_from_cart_form_by_sid(&$form, &$form_state, $sid, $suppress_message_line_item_id = 0) {
  foreach (element_children($form['edit_quantity']) as $id) {
    $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') {
      $wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
      if ($sid == $wrapper->commerce_webform_sid
        ->value()) {
        $form_state['values']['edit_quantity'][$id] = 0;
        if ($line_item_id != $suppress_message_line_item_id) {
          drupal_set_message(t('%product removed from your cart.', array(
            '%product' => $wrapper->commerce_product
              ->value()->title,
          )));
        }
      }
    }
  }
}