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(); 
Amit Dwivedi
1,57020 silver badges38 bronze badges
asked Dec 21, 2015 at 13:09
2
  • Is this a question ? Commented 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 Commented 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();
}
answered Dec 23, 2015 at 6:04
4
  • not work plz update codes. $quoteItem = $quote->getItemByProduct($product); after that line exception occcur in php Commented Dec 23, 2015 at 6:28
  • what is issues are facing? Commented 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 Commented Dec 23, 2015 at 8:14
  • $quoteItem->setQty($productItem['qty']); <-- error Commented Dec 23, 2015 at 8:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.