Reputation: 817
I'm trying to apply filter to the quote items collection, i get the collection using this
$items_collection = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection();
$items_collection->addFieldToFilter('product_id', $_product->getId());
when i print out the select query, the query is correct
$items_collection->getSelect()
But when i iterate through the collection, it is fetching all of the items, it did not apply the filter, does anyone know why?
foreach ($items_collection as $item) {
// Do things....
}
Upvotes: 0
Views: 872
Reputation: 391
Try this. Use getModel instead of getSingleton.
$items_collection = Mage::getModel('checkout/session')->getQuote()->getItemsCollection();
$items_collection->addFieldToFilter('product_id', $_product->getId());
foreach ($items_collection as $item) {
echo $item->getProduct()->getId();
}
Upvotes: 1