dub*_*ons 6 magento cart magento2
我正在使用一些自定义选项动态地将产品添加到Magento2中的购物车.每个产品都具有相同的基本产品ID,具有不同的选项.Represent Product已被正确覆盖,以便添加到购物车的所有产品是分开的.但是使用此代码,添加的第二个产品将丢失它的自定义选项:
$magento_product = $this->productRepository->get('simple-product-1');
$params = array(
'product' => $magento_product->getId(),
'qty' => intval(5),
'options' => array(
'cr_price' => 12.0,
'Product' => "Test P",
'cr_XML' => '<root></root>'
),
);
$this->cart->addProduct($magento_product, $params);
$params = array(
'product' => $magento_product->getId(),
'qty' => intval(10),
'options' => array(
'cr_price' => 14.0,
'Product' => "Test P2",
'cr_XML' => '<root></root>'
),
);
$this->cart->addProduct($magento_product, $params);
$this->cart->save();
Run Code Online (Sandbox Code Playgroud)
只有第一个产品在quote_item_option表中有一个条目.
任何关于为什么或如何修复的想法将不胜感激.
在每次添加之间强制重新加载产品可以修复此问题。
$this->productRepository->get('simple-product-1', false, null, true);
Run Code Online (Sandbox Code Playgroud)
最后一个true参数是forceReload.
| 归档时间: |
|
| 查看次数: |
201 次 |
| 最近记录: |