Tags/topics: 
2
Answers
Vote up!
1
Vote down!

How can I retrieve the total tax applied to an order?

The tax total does not show up in the line items table like other line items (shipping, product, commerce_coupon, etc.), so I don't understand how to get at the data or why these are treated differently from other line items.

Asked by: jmljunior
on August 23, 2012

2 Answers

Vote up!
1
Vote down!

Taxes are calculated during sell price calculation at the unit price level for each product in the cart. The taxed amount is stored in the actual price field using Drupal Commerce's price components system, which tracks the various amounts that got totalled up into a product's price, line item unit price, or order total price.

Since tax data is stored in the price field data along with other price components that result from actions in the price calculation process, you won't find it on its own line item.

This data is available via the API using the commerce_price_component_total() function. You just have to know the name of the price component type you're looking for inside the order total price field's data array.

Ryan Szrama
Answer by: Ryan Szrama
Posted: Sep 21, 2012

Comments

In IRC, agileadam totally just googled his question and found this answer. Love it when things like this work! :D

- Josh Miller on November 8, 2012
Vote up!
0
Vote down!

Thanks for the response. I needed a quick way to get at the data for reporting purposes. I run into issues when I use the API for these tasks as they API calls often load large entities which causes speed and memory issues when applied to thousands of orders.

Answer by: jmljunior
Posted: Nov 28, 2012