Question

I'm working with magento2, I have created custom add to cart product functionality. Now I want update product quantity. I have fetched all cart items and I want update but I am getting incorrect quantities of configurable child product. I have fetched quantity using $item->getQty() inside cart get all items it is working fine with normal product. But I get incorrect cart item quantity for child configurable product. Can we use any other way instead of $item->getQty() I have also configurable child product I'ds.

Was it helpful?

Solution

To get the children quantity you need to check if the item in the cart has children first then go through children, this code will show you how you can get the QTY of the children

if ($item->getHasChildren() ) {
    foreach ($item->getChildren() as $child) {
        // get child quantity by this calling  $child->getQty();
    }
}

where $item is the the cart item

this code works well for me, I hope it will help you.

OTHER TIPS

may be it will work for more then one option

if ($item->getHasChildren() ) {
    foreach ($item->getChildren() as $child) {
        // get child quantity by this calling  $child->getQty();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top