Frage

Kann ich überprüfen, ob sich ein Produkt in meiner Wunschliste befindet? Wenn ja, wie?

War es hilfreich?

Lösung

Option eins. Nähte sauberer.

$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. Nähte schneller

$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();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top