How to get configurable child product quantity from cart item
-
07-01-2021 - |
سؤال
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.
المحلول
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.
نصائح أخرى
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();
}
}