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 Answer 1

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();
10
  • it is showing error - Fatal error: Call to a member function getQty() on a non-object Apr 7, 2017 at 12:05
  • You are sending the $product object to getItemByProduct() right? Apr 7, 2017 at 12:12
  • yes, correct. you are right. Apr 7, 2017 at 12:14
  • I have placed this code in cart.phtml file. Is it correct. ? Apr 7, 2017 at 12:14
  • It doesnt matter where you place the code. It just needs the quote object and product object. Apr 7, 2017 at 12:19

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.