1

OK I really dont get this, I am trying to add a product to the cart and save the quote, this is working great for simple products but I can not get the bundle products to work here is my code

        $params = array(
            'product' => $addId, // the bundle product id
            'qty'     => $addQty, // the qty of the bundle product
            'options' => $optsArray,  .. used for simple products with options

            'bundle_option' => array(
                251 => 1, // add 1 X product 251
                250 => 1, // add 1 X product 250
                249 => 2 // add 2 X product 249
            )

        );

        $quote->addProduct($addProduct, new Varien_Object($params));
        $quote->save(); 

I dont understand what I am doing wrong any help would be greatly appreciated, I cant seem to find what variable sthe bundle_options array expects

0

OK so I found the solution which works perfectly for me I set set the product options like so

$params = array(
        'product' => $addId, // the bundle product id
        'qty'     => $addQty, // the qty of the bundle product
        'options' => $optsArray,  .. used for simple products with options
    );

And then for the default bundle items which I set when I set the products up at the back end

        if($addProduct->getTypeId() == 'bundle') {
            $selectionCollection = $addProduct->getTypeInstance(true)->getSelectionsCollection(
                $addProduct->getTypeInstance(true)->getOptionsIds($addProduct),
                $addProduct
            );
            foreach($selectionCollection as $option) {
                $bundleOption[$option->getOptionId()]       = (int)$option->getSelectionId();
                $bundleOptionQty[$option->getOptionId()]    = (int)$option->getSelectionQty();
            }
            if(!empty($bundleOption)) $params['bundle_option'] = $bundleOption;
            if(!empty($bundleOptionQty)) $params['bundle_option_qty'] = $bundleOptionQty;
        }

Basically this just gets all the listed child products of the bundle and adds them to the params array with the default qtys.

I no there may be other ways of doing this but thought I would post my answer to help fellow developers in need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.