2

I want to get sum of qty of all variations present in cart for a configurable product. For ex.- see below image--

enter image description here

'WHEY PROTEIN ISOLATE-WPI' is a configuration product. In cart it has 2 different variations with qty 1 and 2.

I want to get its total qty i.e 3 (1+2) on same page (cart page), how can I get it.

Although I can do it by looping for each item in cart but it will slow down the cart page, so if any one can suggest another way to do it.

Any idea ?

1

Try this without looping through the cart items.

$quote = Mage::getSingleton('checkout/session')->getQuote();
$product = Mage::getModel('catalog/product')->load($product_id);
$_item = $quote->getItemByProduct($product);
$qty = $_item->getQty();
  • it is showing error - Fatal error: Call to a member function getQty() on a non-object – Shashank Kumrawat Apr 7 '17 at 12:05
  • You are sending the $product object to getItemByProduct() right? – Kingshuk Deb Apr 7 '17 at 12:12
  • yes, correct. you are right. – Shashank Kumrawat Apr 7 '17 at 12:14
  • I have placed this code in cart.phtml file. Is it correct. ? – Shashank Kumrawat Apr 7 '17 at 12:14
  • It doesnt matter where you place the code. It just needs the quote object and product object. – Kingshuk Deb Apr 7 '17 at 12:19

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.