Check whether a product is in the wishlist or not

前端 未结 6 978
不思量自难忘°
不思量自难忘° 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:25

    Since @alexadr.parhomenk s' solution causes undesired results, here's a smaller method that does the trick:

    /**
     * Check customers wishlist on identity product.
     * @param int $productId
     * @return bool
     */
    public function isInWishlist($productId)
    {
        $ids = Mage::registry('wishlist_ids');
        if (!$ids) {
            $productCollection = Mage::helper('wishlist')->getWishlistItemCollection();
            $ids = $productCollection->getColumnValues('product_id');
            Mage::register('wishlist_ids', $ids);
        }
        return in_array($productId, $ids);
    }
    

提交回复
热议问题