How To Sort Cart Items in Magento
/* Fetching the updated cart items */
$items = array();
$cart = Mage::getModel('sales/quote_item')->getCollection()
->setQuote(Mage::getModel('checkout/cart')->getQuote())
->addFieldToSelect('*')
->addOrder('updated_at', 'desc');
foreach ($cart as $item)
{
if (!$item->isDeleted() && !$item->getParentItemId()) {
$items[] = $item;
}
Now you are ready to use $items object.
If you want to use this $items object in cart then
Replace:
foreach($this->getItems() as $_item):
With:
foreach($items as $_item):
And you will get the sorted cart items by last modified date in descending order.
$items = array();
$cart = Mage::getModel('sales/quote_item')->getCollection()
->setQuote(Mage::getModel('checkout/cart')->getQuote())
->addFieldToSelect('*')
->addOrder('updated_at', 'desc');
foreach ($cart as $item)
{
if (!$item->isDeleted() && !$item->getParentItemId()) {
$items[] = $item;
}
Now you are ready to use $items object.
If you want to use this $items object in cart then
Replace:
foreach($this->getItems() as $_item):
With:
foreach($items as $_item):
And you will get the sorted cart items by last modified date in descending order.
How To Sort Cart Items in Magento
Reviewed by Web Technology Funda
on
1:46:00 AM
Rating:
That's a great help you did for me. I was stuck in this problem and thank God that I stumbled upon this post. You have saved my time.
ReplyDeleteRegards,
Prasant Saxena
Software Development Company
You are most welcome Prasant!!! You can also find some other interested magento tips and tricks in my blog... http://pranaydac08.blogspot.in/
Delete