문제

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();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top