Check whether a product is in the wishlist or not

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

    I solved this by the below function. I Hope this may help some one.

    function checkInWishilist($_product){
        Mage::getSingleton('customer/session')->isLoggedIn();
        $session = Mage::getSingleton('customer/session');
        $cidData = $session->isLoggedIn();
        $customer_id = $session->getId();
    
        if($customer_id){
            $wishlist = Mage::getModel('wishlist/item')->getCollection();
            $wishlist->getSelect()
                      ->join(array('t2' => 'wishlist'),
                             'main_table.wishlist_id = t2.wishlist_id',
                             array('wishlist_id','customer_id'))
                             ->where('main_table.product_id = '.$_product->getId().' AND t2.customer_id='.$customer_id);
            $count = $wishlist->count();
            $wishlist = Mage::getModel('wishlist/item')->getCollection();
        }
        else {
            $count="0";
        }
    
        if ($count) :
            return true;
        else:
            return false;
        endif;
    }
    

提交回复
热议问题