我正在用一些自定义选项动态地将产品添加到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();
只有第一个产品在
quote_item_option
表。
任何关于为什么或如何修复的想法都会受到赞赏。