1
votes

I am trying to insert to checkout/cart some bundle product with child items. I am using this code but it work only with simple product.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$product = $objectManager->get('Magento\Catalog\Model\Product')->load(703);

$listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct');

$addToCartUrl =  $listBlock->getAddToCartUrl($product);

echo $addToCartUrl;

I also used this suggest

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$product = $this->productRepository->getById("703");

$magento = array(82=>"103",82 => "112");

$par = array('product' => $product->getId(),'bundle_options' => array( 1 => $magento),'qty' => $qty);

$this->cart->addProduct($_product,$par);

$this->cart->save();

But still doesn't work. Can someone help me? Thanks

1
Did you find exact solution?Ashish Raj

1 Answers

0
votes

// Find the below code for add bundle product.

$product = $this->productRepository->getById("29");
$magento = array(21=>"1",22 => "2", 23 => "3");
$par = array('product' => $product->getId(),
             'bundle_options' => array(  1 => $magento),
             'qty' => $qty);
$this->cart->addProduct($_product,$par);
$this->cart->save();

Reference link : https://magento.stackexchange.com/questions/112788/magento-2-add-bundled-product-to-cart-programmatically