I have created one test script file for add product into cart with custom options. I want display selected custom option of product in cart using programmatically.
Please check my below code:
$productId = 25;
$product = $objectManager->create('MagentoCatalogModelProduct')->load($productId);
$cart = $objectManager->create('MagentoCheckoutModelCart');
$params = array();
$params['options[469]'] = 459;
$params['qty'] = 1;
$params['product'] = 25
$cart->addProduct($product, $params);
$cart->save();
Using objectmanager i have created cart and product object. When i have fired this script in browser, it’s show me error:
MagentoFrameworkExceptionLocalizedException: Please specify
product’s required option(s).
I have already passed custom option in params array. but still it’s show error.
How can i add product into cart with selected custom options ?
Please help me.
Any help would be appreciated.
2
Answers
I have got the solution of this problem. Here is my updated code.
This code is work for me.
please replace your code :
Replace with