Magento 1.9 Cart – How to Programmatically Update a Quote Item

cartmagento-1.9quoteitem

I would like to update the quote item programmatically,

I am trying below

    $walletAmount = Mage::app()->getRequest()->getPost('walletAmount'); //i AM GETTING THIS VALUE THROUGH AN AJAX REQUEST
    $item = Mage::getModel('sales/quote_item')->load($rowQuoteId); // $rowQuoteId CONTAINS item_id OF THE `sales_flat_quote_item` TABLE.
    $item->setWalletAmount($walletAmount);
    $item->getProduct()->setIsSuperMode(true);
    $item->save();

But above this code gives the error message as below,

Fatal error: Call to a member function getStoreId() on a non-object in \app\code\core\Mage\Sales\Model\Quote\Item\Abstract.php on line

Best Answer

Instead of direct call of sales/quote_item model,use checkout/cart singleton model (Mage::getSingleton('checkout/cart')) and it will resolve your issue.

try below code:

$cart=Mage::getSingleton('checkout/cart');
$item = $cart->getQuote()->getItemById($rowQuoteId);
 $item->getProduct()->setIsSuperMode(true);
$item->setWalletAmount($walletAmount)->save();
$cart->save();
Related Topic