Maxed Out
Maxed Out

Reputation: 33

Magento - Check cart for product ID

In Magento CE 1.8.0.0 I am trying to perform the following:

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

I know how to get the cart subtotal, I know how to show static blocks, I believe I can make the if statement work with multiple requirements with &&.

What I cannot figure out for the life of me, is how to check if a particular product ID is in the cart.

Upvotes: 1

Views: 2648

Answers (3)

user6649803
user6649803

Reputation:

<?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.*/
        }
      }
?>

Upvotes: 0

nano
nano

Reputation: 2521

This is what I'm using:

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

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

Upvotes: 0

Marius
Marius

Reputation: 15216

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

The value of $found will tell you if the product is in the cart or not.

Upvotes: 3

Related Questions