0

how to update downloadable product quantity in shopping cart in magento thuough php

$_product = Mage::getModel("catalog/product")->load($p_id);      
$quote = Mage::getSingleton('checkout/session')->getQuote();      
$item = $quote->getItemByProduct($_product);           
$quote->updateItem($item->getId(), array( 'qty' => $p_qty)); getCart()->save(); 
2
  • Is this a question ?
    – Prateek
    Dec 22, 2015 at 14:43
  • yes, i m unable to increase or decrease the quantity of product in shopping cart item in magento 1.8 Dec 23, 2015 at 5:14

1 Answer 1

0

Try this:

$quoteId = 1251; 
$productItem['qty'] = 2;
$productId =  17;
$product = Mage::getModel("catalog/product")->load($productId);
$quote   = Mage::getModel("sales/quote")->load($quoteId);
$quoteItem = $quote->getItemByProduct($product); 

if ($productItem['qty'] > 0) {
    $quoteItem->setQty($productItem['qty']);
}
try {
    $quote->collectTotals()->save();
} catch (Exception $e) {
   echo $e->getMessage();
}
4
  • not work plz update codes. $quoteItem = $quote->getItemByProduct($product); after that line exception occcur in php Dec 23, 2015 at 6:28
  • what is issues are facing?
    – Abdul
    Dec 23, 2015 at 8:09
  • according to customer login, i have to change product quantity in cart but not success . Is there having any update method for update quantity and my product has a downladable product which are E-book and Print-book type contains link Dec 23, 2015 at 8:14
  • $quoteItem->setQty($productItem['qty']); <-- error Dec 23, 2015 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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