我可以检查产品是否在我的愿望清单中?如果是,怎么样?

有帮助吗?

解决方案

选项一。接缝清洁器。

$productId = 1;
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId)
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$hasProduct = false;
foreach ($wishlist->getItemCollection() as $_item) {
    if ($_item->representProduct($product)) {
       $hasProduct = true;
       break;
    }
}
//$hasProduct tells you if the product is in the wishlist

//选项2.接缝更快

$productId = 1;
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$collection = Mage::getModel('wishlist/item')->getCollection()
    ->addFieldToFilter('wishlist_id', $wishlist->getId())
    ->addFieldToFilter('product_id', $productId);
$item = $collection->getFirstItem();
$hasProduct = !!$item->getId();
许可以下: CC-BY-SA归因
scroll top