1

Simple products are added to cart and everything is fine, but bundle products are not added to the basket.

 $params = array(
                    'product' => $products_id,
                    'qty' => $products_count
                );
                $_product = $this->_productRepository->getById( $products_id );
                $this->_cart->addProduct($_product,$params);
                $this->_cart->save();

give an error , 1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Please specify product option(s).

2 Answers 2

0

add the required options to your params array

$params = array(
                    'product' => $products_id,
                    'qty' => $products_count,
                    'options' => array(
                        'attribute_code' => 'value'
                     ),
                );
                $_product = $this->_productRepository->getById( $products_id );
                $this->_cart->addProduct($_product,$params);
                $this->_cart->save();
0
0

Solved.

$data = [
       'qty' => 1, 

         'product' => 8,

         'bundle_option' => [

             3 => 12,  Option ID => Selection ID

          ],

          'bundle_option_qty' => [

               3 => 1,  Option ID => ordered quantity of this option

           ]

          ];

          $_product = $this->_productRepository->getById( $products_id );

          $this->_cart->addProduct($_product,$data);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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