Magento – Check whether a product is in the wishlist or not

helpermagentothemes

I'm working on a Magento theme, and I need to build a function that can check to see whether or not a product has been added to the user's wishlist.

Magento has a "Mage_Wishlist_Helper_Data" helper class, but I have no idea how to build a check-if-already-in-wishlist function. Basically I need to use Magento's wishlist feature to build a favorites list. I want to add a special class to the "add to wishlist" link if the particular product was already added to the user's favorites.

Best Answer

 <?php $wishlist = Mage::getModel('wishlist/item')->load($_product->getId(),'product_id');
      if($wishlist->getId())
          //product is added
      echo "Added! - Product is in the wishlist!";
      else
          //add product to wishlist
      echo "<a href='".$this->helper('wishlist')->getAddUrl($_product) ."'>Add This?</a>";
  ;?>
Related Topic