Reputation: 33
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
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
Reputation: 2521
This is what I'm using:
$quote = Mage::getSingleton('checkout/session')->getQuote();
if ($quote->hasProductId(691)) {
...
}
Upvotes: 0
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