Check whether a product is in the wishlist or not

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

    Since collections are lazy loaded, I am assuming you can do something such as:

    $_product = ...; // some product object you already have
    
    $_productCollection = Mage::helper('wishlist')->getProductCollection()
        ->addFieldToFilter('sku', $_product->getSku());
    
    if($_productCollection->count() > 0) {
        // User already has item in wishlist.
    }
    

    You can do similar filtering on other fields, but SKU should be sufficient in this case.

提交回复
热议问题