function commerce_product_bundle_add_to_cart_form_submit in Commerce Product Bundle 7
Same name and namespace in other branches
- 7.2 commerce_product_bundle.module \commerce_product_bundle_add_to_cart_form_submit()
Submit function to add product bundles to the cart.
Parameters
array $form: The entire add to cart form array.
array $form_state: The actual state of the form.
See also
commerce_product_bundle_update_cart()
commerce_product_bundle_add_to_cart_form()
1 string reference to 'commerce_product_bundle_add_to_cart_form_submit'
- commerce_product_bundle_add_to_cart_form in ./
commerce_product_bundle.module - Builds the add to cart form, for product bundles.
File
- ./
commerce_product_bundle.module, line 772 - Allows the bundling of products in Drupal Commerce.
Code
function commerce_product_bundle_add_to_cart_form_submit($form, &$form_state) {
// The product id of the product we want to add.
$product_id = $form_state['values']['product_id'];
// Add sub products to the cart.
$subproducts = array();
foreach ($form_state['values']['bundle'] as $id => $bundled_item) {
// $subproduct = $form_state['bundle'][$id]['default_product'];
// $bundled_item['product_id'] = $subproduct->product_id;
$subproducts[] = $bundled_item;
}
// If we have a line_item_id, then the product is always in the cart and we
// we have to update the cart.
if (!empty($form_state['line_item']->line_item_id)) {
// Update the product to the specified shopping cart.
$form_state['line_item'] = commerce_product_bundle_update_cart($form_state['values']['uid'], $product_id, $form_state['values']['quantity'], $subproducts, $form_state['line_item']->line_item_id);
drupal_goto('cart');
}
else {
// Add the product to the specified shopping cart.
//field_attach_submit('commerce_line_item', $form_state['line_item'], $form['line_item_fields'], $form_state);
// Return the submitted values of the fields
$response = commerce_product_bundle_add_to_cart($form_state['values']['uid'], $product_id, $form_state['values']['quantity'], $subproducts, $form_state['line_item']);
$form_state['line_item'] = $response['line_item'];
$form_state['bundle_product_line_items'] = $response['sub_line_items'];
}
}