2

I am updating multiple cart items at a glance. And i have updated cart item id's with me. Now i want to get CART item data by its id.

Can you plese help me on this.

8

This should be done with the Mage_Sales_Model_Quote_Item class. If you're updating several items it might be better to use it's collection tho.

$the_item_ids = array(2,5,6,8);

$collection = Mage::getModel('sales/quote_item')->getCollection()
   ->addFieldToFilter('item_id', array('in' => $the_item_ids));

foreach($collection as $item)
{
  var_dump($item->getData());
}
3
  • Thanks. Can i do like this: $cartItem = Mage::getSingleton('checkout/cart')->getQuote()->getItemById($item['itemId']);
    – Sivakumar
    Dec 21 '13 at 11:11
  • @SelectSmile I'm not sure if that method exists but if so, yes
    – Sander Mangel
    Dec 21 '13 at 19:24
  • 2
    AFAIK getItemById() is defined in Varien_Data_Collection and should be available in all collections.
    – Vicary
    Dec 19 '14 at 8:26
1

we can load quote item object by item_id directly.

$itemObject = Mage::getModel('sales/quote_item')->load($itemId);

This is working fine for me.

0

Use this because of _assignOptions and _assignProducts in Mage_Sales_Model_Resource_Quote_Item_Collection:

$collection = Mage::getResourceModel('sales/quote_item_collection')
     ->setQuote($quote) // this is the model not an id.
     ->addFieldToFilter('item_id', array('in' => $quoteItemIds));

If no quote is set, it won't work.

0

To be straightforward this is what you need to load a quote(cart) item by its id

$_quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItemId = (int) $this->getRequest()->getParam('item_id');
$_quoteItem = Mage::getModel('sales/quote_item')
              ->setQuote($_quote)
              ->load($cartItemId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.