4

I'm trying to create a link to remove an item from the wishlist if it's there. The URL is returning /wishlist/index/remove instead of the correct URL which from what I've seen online should be /wishlist/index/remove/item/[ID]. Trying that URL manually doesn't work. This is my way of getting the remove URL:

$_wishlistRemoveUrl = $this->helper('wishlist')->getRemoveUrl($_product);
5
  • why do you have both magento-1.7 and magento-enterprise tags? Commented Mar 21, 2013 at 13:02
  • Were using EE but the answers for CE work just as well.
    – kel
    Commented Mar 21, 2013 at 15:20
  • Then it makes no sense to mention any of them ;) Commented Mar 21, 2013 at 16:11
  • Generally if you're asking a question then you're probably not sure if it will apply to both EE and CE, and seeing as wishlists apply to both versions I don't see any harm in tagging this with both EE and CE tags. I think this question should definitely have a 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. Commented Mar 22, 2013 at 0:52
  • It doesn't work for me. The parameters are $_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/ ? Commented Feb 28, 2014 at 13:32

1 Answer 1

8

First, an overview of how wishlists work:

  1. Each wishlist is stored in the database with its own ID
  2. Each product added to a wishlist is assigned a wishlist_item_id
  3. 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

1
  • that was an excellent answer. Thanks for explaining that to me more and your solutions work perfectly!
    – kel
    Commented Mar 21, 2013 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.