0

I use following code to get cart information:

$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach( $cart_items as $items )
{
        $items->getQty();
}

In above code $items->getQty() always return "float(1)" for child product.

For Example I have a configurable product say "2-disk set" which has associated product as "cds & dvds". I have add quantity 2 for "cds & dvds" in cart but $items->getQty() return "float(1)".

How to get correct quantity for child product?

Thanks in advance.

2

Try getAllVisibleItems() function

$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach( $cart_items as $items )
{
        $items->getQty();
}

Ref : https://techbandhu.wordpress.com/2013/11/29/magento-what-is-the-difference-between-getallvisibleitems-and-getallitems/

0

I found my solution from link:

$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach( $cart_items as $items )
{
    STATIC $qty='';
    if($items->getProductType() == 'configurable')  //configurable products
    {
        $qty = $items->getQty();
        continue;
    }
    else                                            // non-configurable product
    {
        if (!$items->getParentItem())               // products which have not parent product 
        {
            $qty = $items->getQty();
        }
    }
    echo $qty;
}

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.