First, an overview of how wishlists work:
- Each wishlist is stored in the database with its own ID
- Each product added to a wishlist is assigned a
wishlist_item_id
- This ID is not the same as the
product_id
For this reason you can't just pass in a product ID to the remove URL because it's actually referencing the product's wishlist_item_id
.
This explains why you are getting a blank url ("/wishlist/index/remove"), because when you pass in the product it doesn't have the required wishlist_item_id
, you have to retrieve this in a different way.
To get around this, there is a method in Mage_Wishlist_Model_Item
you can use to get a wishlist item by product ID:
/** @var $_wishlistHelper Mage_Wishlist_Helper_Data */
$_wishlistHelper = $this->helper('wishlist');
/** @var $_wishlist Mage_Wishlist_Model_Wishlist */
$_wishlist = $_wishlistHelper->getWishlist();
/** @var $_wishlistItem Mage_Wishlist_Model_Item */
$_wishlistItem = Mage::getModel('wishlist/item');
$_wishlistItem->loadByProductWishlist(
$_wishlist->getId(),
$_product->getId(),
$this->helper('core')->getStoreId()
);
$_wishlistRemoveUrl = $_wishlistHelper->getRemoveUrl($_wishlistItem);
Or the shorter way:
$_wishlistItem = Mage::getModel('wishlist/item')->loadByProductWishlist(
$this->helper('wishlist')->getWishlist()->getId(),
$_product->getId(),
$_product->getStoreId()
);
$_wishlistRemoveUrl = $this->helper('wishlist')->getRemoveUrl($_wishlistItem);
This code has been tested in blocks of type Mage_Catalog_Block_Product_List
and Mage_Catalog_Block_Product_View
magento-1.7
andmagento-enterprise
tags?catalog
tag though, as you're trying to display wishlist remove URLs on catalog pages. No biggie, just makes it easier for people to find in the future.$_product->getId()
and$_product->getStoreId()
Right? I'm trying to find remove_id. Becauce remove links almost same but remove_id. How can I find remove_id in this link: xx.com/wishlist/index/remove/item/$remove_id/ ?