A Guide to Magento 1 var_dump for Orders, Invoices, or Quotes
A Guide to Currency & Prices for Orders, Invoices, and Quotes
A Guide to Currency & Prices for Orders, Invoices, and Quotes

A Guide to Currency & Prices for Orders, Invoices, and Quotes

Published February 18, 2011 in Development
Llama Loose In LA: Speaks At Magento Imagine Conference
February 3, 2011
Introducing Wiz, a CLI Tool for Magento
March 8, 2011

If you’ve ever looked at a var_dump() or var_export() of an order, quote, or invoice object, you might have noticed there are a long list of numbers that are present in that object. Here is a sample taken from an order object:

There are a lot of fields here and they can be quite confusing.  The goal here is to help you decipher the numbers and explain what they mean.

 

Note: If the names of those variables don’t look familiar, it’s probably because you won’t see them in the code anywhere. They are accessible via an object’s accessor methods. So to get the ‘base_grand_total’, you’d need to call $object->getBaseGrandTotal(). Sorry for the confusion!

For starters, though, let’s cover a little background on currency.

Currency

It wouldn’t be a good article about money with some discussion about currency. Most people probably won’t have to worry about currency conversion, however, a look at price information would be incomplete without touching on it since it is vital to decoding it. Lines 139 through 155 in app/code/core/Mage/Sales/Model/Quote.php talk about the currency logic Magento uses as well as what to use and not use when dealing with these values.

Magento provides a hierarchal system for managing a currency. Currency can be set globally, at the store or “base” level (for display), and then at the quote and order level based on the customer’s preference. The global currency is used in the backend for setting up prices on products. Even if a store is configured to use a different currency, the prices for the objects will be converted from the base currency to the currency of the store. This is important because decoding the names of the values on the object will require us to know how Magento handles dealing with multiple currencies. (Even if only one is configured and used.)

Keeping in mind the three tiers, if we look closely at the object we can see the three tiers of currency information stored in the values:

In red, we see the global currency as well as the conversion rate from the base (or the store) rate to the global rate. In green, we see nine fields. In blue, there are eight fields. You can tell from these values that we are looking at the dump from an order object because one of the fields listed is order_currency_code. Since we are looking at an order, we know that the fields that are not prefixed with base_ or global_ are in the currency of the order. The green fields are nothing more than the order’s fields recalculated in the base (or store) currency for ease of access.

Totals, Amount, Tax, & Shipping

So we’ve essentially got seven distinct values to work with:

  • discount_amount
  • grand_total
  • shipping_amount
  • shipping_tax_amount
  • subtotal
  • subtotal_incl_tax
  • tax_amount

Discount Amount

This is the dollar value of the discount that was applied to the order.

Shipping Amount

The amount paid for shipping on the entire order.

Shipping Tax Amount

This amount of tax that is paid on the shipping.

Subtotal

The cost of just the products without shipping, taxes, or discounts.

Subtotal Including Tax

This amount of tax that is paid on just the products.

Grand Total

This is the total amount of the order after includes taxes, shipping, and discounts. For an order or quote, this is what would be paid by the customer.

Closing Thoughts

How Magento does it’s calculations is highly configurable. There are many options in the backend that affect how taxes, shipping, and discounts affect the totals and values we’ve seen in this article.

To summarize, Magento stores copies of each of the values in both the currency that the current invoice, order, or quote is in as well as the currency of store.  This allows a programmer to see and use both values.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Recent PostsView all
November 4, 2021

How to prepare for holiday 2021: A winter shopping season like no other

With the holiday season comes a frenzy of online shopping activity. For retail businesses, this busy season is a critical period when an essential amount of […]
October 15, 2021

Classy Llama Wins 2021 Comparably Awards for Best Perks&Benefits, Best Work-Life Balance

Classy Llama, Springfield’s only full-service eCommerce agency, has been placed on the top 50 list for Comparably.com’s Best Perks&Benefits Award, as well as their Best Work-Life […]
September 15, 2021

Classy Llama Awarded #3 Best Place to Work by Biz417

Springfield, MO — Classy Llama has been awarded the number 3 spot on the Biz417 Best Places to Work Top 20 for 2021.  This award is […]