In Magento/Sales/view/frontend/templates/order/items/renderer/default.phtml, I'm trying to get the quantity backordered for any relevant products. I want to do this regardless of order status.
However, when I call $_item->getQtyBackordered(), it works only when the product is a simple product. If the product is a configurable product, getQtyBackordered() returns null because the item that's loaded is the configurable product itself, not the simple product associated with it.
How can I load the simple product to get the quantity backordered? Calling $_item->getChildrenItems() also returns nothing. Or is there another way to go about it?
Hello @phabeeb,
To get the children quantity you need to check if the item has children first then go through children, this code will show you how you can get the backorder QTY of the children
if ($item->getHasChildren() ) {
foreach ($item->getChildren() as $child) {
// get child quantity by this calling $child->getQtyBackordered();
}
}
I hope it will help you.
--
If my answer is useful, please Accept as Solution & give Kudos
Hi @gelanivishal,
Thanks for the reply. I've tried this, but $item->getHasChildren() doesn't return anything. It's like $item is suddenly considered not to have children, even though it does. Is getHasChildren() for bundled products only? Or should it work for configurable products, too?
Alternatively, its there another way to get the backordered quantity?
Thanks.