I had to check the POST variables sent to the cart url from the frontend to see this.
These were the variables sent for one package:
bundle_option[1][] 17 bundle_option[1][] 19 bundle_option_qty[1][17] 1 bundle_option_qty[1][19] 1 product 833 qty 2 related_product
From this, I realized that bundle_option[1] refers to Option 1 in the bundle. I also understood that the values ββof the indices bundle_option[1][0]=17 and bundle_option[1][1]=19 - 17 and 19 refer to selection_id .
Analysis of the form in the interface showed my list selection_id. I decided that the selection identifier will change as soon as the package is changed in Admin> Manage Products, so I used the search to get the selection identifiers, and not their hard coding.
The code I ended up in was as follows:
$json_string = isset($_POST["json"])? $_POST["json"] : null; if (!is_null($json_string)) { $json_obj = json_decode($json_string, true); #define cart $cart = Mage::getSingleton('checkout/cart'); #look-up bundle selection ids $bundled_product = new Mage_Catalog_Model_Product(); $bundled_product->load(833); #833 = test bundle $selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection( $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product ); $bundled_items = array(); foreach ($selectionCollection as $option) { $bundled_items[$option->product_id] = $option->selection_id; } #get bundle items, quantities $bundle = array(); $bundle_qty = array(); for ($i=0; $i<count($json_obj['basket']['products']); $i++) { $product_id = (int)$json_obj['basket']['products'][$i]['id']; $selection_id = $bundled_items[$product_id]; if(!in_array($selection_id,$bundle)) array_push($bundle,$selection_id); if (isset($bundle_qty[$selection_id])) $bundle_qty[$selection_id] += (int)1; else $bundle_qty[$selection_id] = (int)1; } #add to bundled product to cart $options = array('product'=>833, 'related_product'=>null, 'bundle_option'=>array(1=>$bundle), 'bundle_option_qty'=>array(1=>$bundle_qty), 'qty'=>(int)$json_obj['basket']['quantity'] ); $cart->addProduct($bundled_product, $options); $cart->save(); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); $message = $this->__('Notice: %s item(s) were successfully added to your shopping cart.', $i); Mage::getSingleton('checkout/session')->addSuccess($message); }
Hope this saves you a lot of time!
Edit
Still trying to decide why bundle_option_qty does not set the quantity (all elements: qty: 1 are added to the package product)
Edit 2
It turned out that the built-in function of adding additional items to the basket cannot add several items to the basket. Having studied the problem, I found that the package number function was an extension of Kabel BundlePlus , it was probably installed incorrectly by previous developers, so I downloaded it again and reinstalled the plugin, and now the bundle_option_qty works both in the interface and in my plugin !