I'm trying to build a custom payment module for magento 2 and i have a function in my payment module that is called on the success page. The problem is that i can't get the items quantity. I can get the name, price and sku but not the quantity. Below a bit of the code:
$order = $this->getOrder($orderId);
$items = $order->getAllItems();
$i = 1;
foreach($items as $item) {
$product = $item->getProduct();
$item = "<item id='".$i."'>";
$item.= "<name>".$product->getName()."</name>";
$item.= "<infos>".$product->getName()."</infos>";
$item.= "<amount>".$product->getPrice()."</amount>";
$item.= "<categoryId>".$category_id."</categoryId>";
$item.= "<quantity>".intval($item->getQtyOrdered())."</quantity>";
$item.= "<reference>".$product->getSku()."</reference>";
$item.= "</item>";
$xmlItems[] = $item;
$i++;
}
When using $item->getQtyOrdered()
. i get the following error:
Fatal error: Call to a member function getQtyOrdered() on string on line 139.
And when using $product->getQtyOrdered()
the result is null.
Now the interesting part is that i use PhpED to debug the code and when i add to the watch list this $item->getQtyOrdered()
the result is 1.0000
.
What am i missing?