1

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

6

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();
1

Here's the only place where getStoreId() is mentioned in Mage_Sales_Model_Quote_Item_Abstract:

 $product = $this->_getData('product');
        if ($product === null && $this->getProductId()) {
            $product = Mage::getModel('catalog/product')
                ->setStoreId($this->getQuote()->getStoreId())
                ->load($this->getProductId());
            $this->setProduct($product);
        }

It seems that the issue in $this->getQuote(). Try to check if the quote exists. Anyway, you can set the product manually:

$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);
$product = Mage::getModel('catalog/product')
    ->setStoreId($item->getStoreId())
    ->load($item->getProductId());
$item->setProduct($product);
$item->getProduct()->setIsSuperMode(true);
$item->save();

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.