add catalog product in wishlist programmatically in magento

青春壹個敷衍的年華 提交于 2019-12-08 12:24:42

问题


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);

回答1:


You have to change first line

$wishlist=Mage::getModel('wishlist/wishlist')

to

$wishlist = Mage::helper('wishlist')->getWishlist();


来源:https://stackoverflow.com/questions/21423186/add-catalog-product-in-wishlist-programmatically-in-magento

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!