I tried with add to cart bundle product but getting error when run the custom code. you can see below code for bundle product.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$quote = $objectManager->get('\Magento\Checkout\Model\Cart');
$_product = $objectManager->get('\Magento\Catalog\Model\Product')->load(28);
$params = array (
'product' => 28, // product id
'qty' => 1, // product qty
'related_product' => null,
'bundle_options' => array(
6 => 1, // 6 is bundle sub product id and 1 is option id
2 => 2
)
);
$quote->addProduct($_product, $params);
$quote->save();
and when i run the custom above code you can see below error.
1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): Please specify product option(s).
can you please suggest what is the issue on code. Thanks