Understanding Magento CE 1.7 Total Prices: Grand_Total vs Sub_Total
Magento Commerce Edition (CE) 1.7 introduced significant improvements in its pricing structure, allowing more flexibility for enterprise-level businesses. However, the new naming conventions for total prices can be confusing at first glance.
Understanding the Basics
Before diving into the specifics, let’s clarify a few terms:
- Sub-Total: This represents the sum of all items in your cart before any discounts or taxes are applied.
- Tax Total: This includes the subtotal plus tax amounts from all taxable items.
- Discount Total: Subtracts the discount amount (if applicable) from the subtotal.
Grand_Total vs Sub_Grand_Total
Grand_Total
$order->getGrandTotal() in Magento CE 1.7 returns the total amount of an order after applying discounts and all taxes, but before shipping costs are added.
Here’s a code example:
// Retrieve the grand total of the current order
$grandTotal = $order->getGrandTotal();
// Output: "1234.56"
echo 'Grand Total: '.number_format($grandTotal, 2);
Sub_Grand_Total
$order->getSubTotal() returns only the sum of all item prices before any tax or discount calculations.
In other words, it’s equivalent to the subtotal you would see before taxes and discounts are applied during checkout.
The Magento Pricing Structure
To understand the flow, let’s look at how Magento calculates these totals:
- Item Price Calculation: Magento first multiplies each product’s price by its quantity.
- Sub-Total Calculation: It adds up all item prices to get the sub-total. This is represented by
$order->getSubTotal()in CE 1.7. - Tax Calculation: For each taxable item, Magento calculates and adds the appropriate tax amount based on your tax configuration.
- Discount Application: If a discount coupon is applied, it’s subtracted from the sub-total at this stage.
- Grand Total Calculation: Finally, Magento sums up all item prices (sub-total), taxes, and discounts to arrive at the grand total.
Conclusion: Choosing the Right Total
The choice between getSubTotal(), getTaxTotal(), or getGrandTotal() depends on what you want to display:
- Use
$order->getSubTotal()if you need the raw item prices before taxes and discounts. - Use
$order->getGrandTotal()for the final price paid, including all taxes and discounts but excluding shipping costs.
Remember, these methods are used within your Magento extensions or customizations. Understanding each total is key to building accurate pricing logic in your modules.
To learn more about Magento’s order management, I recommend checking out our comprehensive guide on Laravel Company.