我想在购物车页面上使用自定义标签在购物车中添加产品
I want to add products in cart with custom labels on cart page
我尝试了多种方法以编程方式将产品添加到购物车,但我想显示报价项目标签以及一个购物车页面。谁能帮我做这个或任何参考资料?
这是您要查找的代码;)
<?php
$loadProductData = Mage::getModel('catalog/product')->load($productId);
$quote = Mage::getSingleton('checkout/session')->getQuote();
$OrderquoteItem = Mage::getModel('sales/quote_item');
$quoteItem = $OrderquoteItem->setProduct($loadProductData);
//custom options to show user on cart page
$a_options = array(
'options' => array(
'label' => 'OptionLabel :',
'value' => "OptionaValue",
));
//add above options array to this cart item which is going to get added on cart
$quoteItem->addOption(array(
'code' => 'additional_options',
'value' => serialize($a_options),
));
// set price and quantity
$quoteItem->setQuote($quote)
->setQty($productOptions['qty'])
->setOriginalCustomPrice($productOptions['price'])
->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
您可以在观察者中使用以下代码。
$item = ( $item->getParentItem() ? $item->getParentItem() : $item);
$additionalOptions = array(array(
'code' => 'option_code',
'label' => 'Some_option_Label',
'value' => 'Option_Value'
));
$item->addOption(array(
'code' => 'additional_options',
'value' => serialize($additionalOptions),
));
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
我尝试了多种方法以编程方式将产品添加到购物车,但我想显示报价项目标签以及一个购物车页面。谁能帮我做这个或任何参考资料?
这是您要查找的代码;)
<?php
$loadProductData = Mage::getModel('catalog/product')->load($productId);
$quote = Mage::getSingleton('checkout/session')->getQuote();
$OrderquoteItem = Mage::getModel('sales/quote_item');
$quoteItem = $OrderquoteItem->setProduct($loadProductData);
//custom options to show user on cart page
$a_options = array(
'options' => array(
'label' => 'OptionLabel :',
'value' => "OptionaValue",
));
//add above options array to this cart item which is going to get added on cart
$quoteItem->addOption(array(
'code' => 'additional_options',
'value' => serialize($a_options),
));
// set price and quantity
$quoteItem->setQuote($quote)
->setQty($productOptions['qty'])
->setOriginalCustomPrice($productOptions['price'])
->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
您可以在观察者中使用以下代码。
$item = ( $item->getParentItem() ? $item->getParentItem() : $item);
$additionalOptions = array(array(
'code' => 'option_code',
'label' => 'Some_option_Label',
'value' => 'Option_Value'
));
$item->addOption(array(
'code' => 'additional_options',
'value' => serialize($additionalOptions),
));
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);