Issue
I'm trying to get the subtotal of each row/line item in the success page but I'm not sure what to use.
I've tried getRowTotal()
and getRowTotalInclTax()
but both are showing up blank.
I'm able to get the whole cart subtotal but want I need is the individual product subtotal.
Here's part of the code I'm using:
// Get order details
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($block->getOrderId());
// Get Each Product Details
$items = $order->getAllItems();
foreach($items as $i) {
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($i->getProductId());
echo $product->getName();
echo $product->getSku();
echo $product->getRowTotal(); // This is where its just coming back blank/null
}
Solution
There you are loading the product entity: The product entity cannot contain the information of the order.
You must use the Order Item entity that you already use to have the total row
Something like this :
// Get order details
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($block->getOrderId());
// Get Each Product Details
$items = $order->getAllItems();
foreach($items as $i) {
echo $i->getProduct()->getName();
echo $i->getProduct()->getSku();
echo $i->getRowTotal();
}
Answered By - Walid Fitouri Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.