Question

chèque Puis-je si un produit est dans ma liste? Si oui, comment?

Était-ce utile?

La solution

d'une option. plus propre Seams.

$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

// Option 2. Seams plus rapide

$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();
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top