Magento - 检查购物车是否有产品编号

时间:2014-02-17 17:17:49

标签: php magento e-commerce magento-1.8

在Magento CE 1.8.0.0中,我尝试执行以下操作:

if cart subtotal is equal to or greater than 99
and has product ID 691
    show this static block.

我知道如何获得购物车小计,我知道如何显示静态块,我相信我可以使用&&使if语句符合多个要求。

我无法弄清楚我的生活,是如何检查特定产品ID是否在购物车中。

3 个答案:

答案 0 :(得分:3)

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$found = false;
foreach ($items as $item) {
    if ($item->getProductId() == 691){
        $found = true;
        break;
    }
}

$found的值会告诉您产品是否在购物车中。

答案 1 :(得分:0)

这就是我正在使用的:

$quote = Mage::getSingleton('checkout/session')->getQuote();

if ($quote->hasProductId(691)) {
... 
}

答案 2 :(得分:0)

<?php 
    $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
        foreach($items as $item)
        { 
           if ($item->getProductId()==691){
            /* Here, you can display any message or something else.*/
        }
      }
?>
相关问题