Check whether a product is in the wishlist or not

前端 未结 6 1018
不思量自难忘°
不思量自难忘° 2021-01-15 02:51

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

6条回答
  •  感动是毒
    2021-01-15 03:22

    I found this solution after checked select query of Mage::helper('wishlist')->getWishlistItemCollection(). I hope this solution help to someone.

       /**
         * Check customers wishlist on identity product.
         * @param Mage_Catalog_Model_Product $_product
         * @return bool
         */
        private function _isInWishlist($_product)
        {        
            $_productCollection = Mage::helper('wishlist')->getWishlistItemCollection()
            ->addFieldToFilter('product_id', $_product->getId());
    
            if ($_productCollection->count()) {
                return true;
            }
    
            return false;
        }

提交回复
热议问题