在magento中以编程方式在愿望清单中添加目录产品 [英] add catalog product in wishlist programmatically in magento
本文介绍了在magento中以编程方式在愿望清单中添加目录产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了带有自定义选项的产品,并在自定义页面上显示了该产品的详细信息.现在,我想将产品添加到用户已填充的自定义选项的愿望清单中. 如果我只需要在愿望清单中添加产品,则可以简单地使用以下代码.
I have created a product with custom option and I have showed the detail of this product on a custom page. Now I want to add the product in wishlist with filled custom option by user. If i have to just add the product in wishlist, I can simply use the following code.
<a href="'.Mage::helper("wishlist")->getAddUrl($_product).'" class="link-cart">Add to Wishlist /a>
但是我想插入带有自定义选项的产品.为此,我使用了以下代码,但它给了我错误无法指定愿望清单"
but i want to insert the product with custom option. For this i have use following code but it gives me error "Cannot specify wishlist"
$wishlist=Mage::getModel('wishlist/wishlist') ;
$storeId = Mage::app()->getStore()->getId();
$model = Mage::getModel('catalog/product');
$_product = $model->load($data['productId']);
$params = array('product' => $data['productId'],
'qty' => 1,
'store_id' => $storeId,
'options' => array( 'optionId' => 'option value',
'optionId2' => 'option value2',
)
);
$request = new Varien_Object();
$request->setData($params);
$result = $wishlist->addNewItem($_product, $request);
推荐答案
您必须更改第一行
$wishlist=Mage::getModel('wishlist/wishlist')
到
$wishlist = Mage::helper('wishlist')->getWishlist();
这篇关于在magento中以编程方式在愿望清单中添加目录产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文