[英]Add to cart with product custom option in Magento
I have a virtual product with custom option (type-1 and type-2). 我有一个带有自定义选项(类型1和类型2)的虚拟产品。 Price may change depend on type.
价格可能会因类型而异。 How can I add to cart with this option directly and change the price depend on custom option.
如何直接使用此选项添加到购物车并根据自定义选项更改价格。 I tried this code but it doesn't work.
我试过了这段代码,但是没有用。
<?php
// the ID of the product
$product_id = "123";
$product = Mage::getModel('catalog/product')->load($product_id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$params = array(
'product' => $product_id,
'qty' => 1,
'options' => array(
'options' => array(
'7462' => 'Type Option Id' ,
'3731' => 'Type-1',
)
)
);
$cart->addProduct($product, $params);
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$this->_redirect('checkout/cart');
?>
Please try following code to add option to your product : 请尝试以下代码为您的产品添加选项:
$quoteItem->addOption(new Varien_Object(
array(
'product' => $quoteItem->getProduct(),
'code' => 'additional_options',
'value' => serialize($a_options)
)
));
Ref Here : add product to cart with custom options 在这里引用: 使用自定义选项将产品添加到购物车
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.