我想使用REST API将捆绑产品添加到购物车中
POST : http://localhost/magento/rest/default/V1/carts/mine/items
input :
{
"cartItem": {
"sku": "Bundle Product",
"qty": 4,
"quote_id": "29"
}
}
但我从magento得到一个错误:“警告: Invalid argument supplied for foreach() in /opt/lampp/htdocs/magento/vendor/magento/module-bundle/Model/CartItemProcessor.php on line 87"
加入购物车简单的产品正在工作:
{
"cartItem": {
"sku": "Simple Product",
"qty": 4,
"quote_id": "29"
}
}
请帮我解决这个问题 .
1 回答
这是解决方案 . 它基于Magento2(我看到不同的标签,但我认为,根据错误信息,你想要它用于Magento2) .
假设我们的包由SKU "bundle01"和ID 123标识 .
首先,让我们从产品中获取一些信息:
GET /products/bundle01?searchCriteria
并注意
"extension_attributes" --> "bundle_product_options"
部分,特别是与您的产品相关的option_id
字段 . 并且不要考虑与产品相关的所有product_links
- >id
值 .假设我们有3个产品分别为option_id 643,644,645和id 704,705,706 .
有了所有这些信息,以下是将捆绑产品添加到购物车的正文: