问题
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