How to get row total of each product in an order on Magento 2?

How to get row total of each product in an order on Magento 2?

August 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get row total of each product in an order on Magento 2?

Magento 2: Calculating Individual Product Subtotals on Success Page

In Magento 2, retrieving individual product subtotals for an order isn’t as straightforward as you might expect due to the layered nature of pricing calculations. The getRowTotal() and getRowTotalInclTax() methods typically return null because they are intended to calculate totals at a higher level—they don’t handle item-level pricing logic.

To calculate the subtotal for each product, we need to leverage Magento’s tax calculation features and perform the calculation manually. Here’s how you can achieve this:

Understanding Magento’s Tax Calculation

Magento calculates taxes based on the shopping cart price rules and tax application rules configured in your store settings. The total tax amount is calculated for the entire cart, not individually per item.

When a product is added to the cart, Magento applies all applicable tax rates to determine the final price. This means that even if you have multiple items with different base prices and taxes, the individual tax amounts aren’t directly accessible through the order or item models.

To retrieve an accurate subtotal for each item, you need to calculate it yourself using Magento’s core tax calculation model.

Retrieving Individual Product Subtotals

Here’s how you can modify your code to correctly calculate the subtotal for each product:

// 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();

// Load tax calculation model
$taxCalculationModel = $objectManager->get('\Magento\Tax\Model\Sale\Total\Quote\TaxManagement');

// Array to store product subtotals
$productSubtotals = [];

foreach($items as $i) {
    // Get the base row total (without tax)
    $baseRowTotal = $i->getBaseRowTotal();

    // Calculate tax for this item
    $taxAmount = $taxCalculationModel->calcTaxAmount(
        $baseRowTotal,
        $i->getTaxPercent(),
        true,  // Include tax in price
        false, // Don't round the tax amount
        $order->getStore()->getId()
    );

    // Calculate total for this item (base row total + tax)
    $total = $baseRowTotal + $taxAmount;

    // Store subtotal for each product
    $productSubtotals[$i->getSku()] = $total;
}

// Now you can access the individual product subtotals in $productSubtotals array

In this modified code, we first retrieve the base row total for each item ($baseRowTotal), which represents the price before any taxes are applied. We then use Magento’s tax calculation model to calculate the tax amount for that specific item.

Once we have both the base row total and the calculated tax amount, we simply add them together to get the final subtotal for that product.

Conclusion

Calculating individual product subtotals in Magento 2 requires a deeper understanding of how taxes are applied at the cart level. By leveraging Magento’s core tax calculation model, you can manually calculate the subtotal for each product and avoid relying on methods like getRowTotal() and getRowTotalInclTax(), which don’t handle item-level pricing logic.

Remember to use this approach sparingly and only when necessary, as manual calculations can introduce complexities in your codebase. If possible, try to optimize your tax configurations or use Magento’s built-in subtotal functionalities for the main cart view.

For more insights on Magento 2 development best practices and advanced techniques, feel free to explore our other blog posts at Laravel Company.

Happy coding!

Magento 2 Checkout Catalog Configuration

Our network