php - Magento: Is a certain product in the cart? -
on list.phtml page, want php script able tell whether product in cart, based on it's sku.
so conditional theoretically this:
$_sku = 123; if($_sku->isinbasket() == true){ echo 'product: ' . $_sku . ' in cart'; } how can achieved realistically?
fetch data checkout session , check product exits in current session
$quote = mage::getsingleton('checkout/session')->getquote(); $foundincart = false; foreach($quote->getallvisibleitems() $item) { if ($item->getdata('sku') == $_sku) { $foundincart = true; break; } } it bad check sku.
because of whenever configurable product cart simple product sku in db.
so need check using product id.for case need find id of $sku mage::getmodel('catalog')->loadbysku($sku); before start of products foreach loop.
$_skupid=''; $matchpro=mage::getmodel('catalog')->loadbysku($sku); if($matchpro->getid()){ $_skupid=$matchpro->getid(); } $quote = mage::getsingleton('checkout/session')->getquote(); $foundincart = false; foreach($quote->getallvisibleitems() $item) { if ($item->getdata('prodduct_id') == $_skupid) { $foundincart = true; break; } }
Comments
Post a Comment