Sorry, if this isn't the correct place to post this question. But getting no responses on DrupalCommerce.org
Is it possible to display each individual component of the order total as it's own field in a view? Either by replacement pattern or rewrite output with php code to show that individual component for the order total?
I am setting up some views to show Sales Reports for the Commerce sales. Specifically using the views to export to a CSV file with all the order details. I have things working pretty good, however I'm struggling with showing the order total components (Subtotal, Shipping, Discounts, Tax, Order Total) as separate fields, instead of just the total.
I'm displaying the "Commerce Order: Order total". When I have the Formatter set to "Formatted amount" I get the full total as a $ amount. If I set it to "Formatted Amount with Components", it outputs a table with Subtotal, Shipping, Tax, Order Total (similar to what I see in the order view). My problem is that table doesn't export to CSV (it just leaves the column blank). but I'm trying to have each individual item show in it's own column.
Need something like "Commerce Order: Order Total: Tax" ??
I have played with the Commerce Reporting module but it isn't really outputting what I need. And the tax report is very limited.
Thanks for any help or direction anyone can provide.
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedNope, there's no way, though you should look at how the tax report works in http://drupal.org/project/commerce_reports. If you really need it to work the way you've described, then you'll need to define your own Views fields that essentially wrap the order total field handler to get the right data and then provide a different render function to extract just the price component you want.
Comment #2
tmsimont CreditAttribution: tmsimont commentedI think this would be a very important feature of any e-commerce back end reporting mechanism. If the receipt separates the shipping/tax/donation other components, why wouldn't views?
Comment #3
rszrama CreditAttribution: rszrama commentedMy original comment probably wasn't clear enough - by no way, I mean that we literally cannot do this, not that I just didn't want to. Price component data is not stored in a way that makes it queryable by Views or direct SQL queries - it's sadly tucked away in the price field's data array. There are other issues in the queue that address the idea of running totals of these things, though, and there's the tax report in the module I've linked above that demonstrates the idea of batch processing orders to extract specific price components for reporting purposes.
Comment #4
tmsimont CreditAttribution: tmsimont commentedFor anyone else looking for the same feature, I was able to accomplish something like this with Views PHP
The code I used in the field code looks like this:
That would require an order number field, and shows the shipping item in its own field. Something similar could be used I'm sure for taxes or other order total components.
Comment #5
tmsimont CreditAttribution: tmsimont commentedoops sorry didn't mean to override your status i think we posted at the same time.
Comment #6
rcharamella CreditAttribution: rcharamella commentedCould you post some more details about how you accomplished this? I'm trying to do the same thing, but coming up empty. Any more specifics would be helpful.
Comment #7
alberto56 CreditAttribution: alberto56 commentedOn admin/commerce/config/checkout/form/pane/checkout_completion_message, I am using replacement patterns to display the total amount. My client would like to display the tax information here, which is reasonable. If anyone has managed to do this, I'd love to hear from you!
Comment #8
TolstoyDotCom CreditAttribution: TolstoyDotCom commentedApparently to get the tax you use code like that in #4, but instead of checking for shipping you use this pseudocode:
Then you add up the taxes. I don't know if there's a function to do that or how stable the array format is.
commerce_unit_price seems to have the same data as commerce_total.
The tax values have the name 'tax|new_york_state_tax' but I don't know if that's installation-specific.
$data_array[ 'component' ]
contains other things like discounts.Comment #9
rszrama CreditAttribution: rszrama commentedThere's actually a helper function for getting the total tax amount in the Tax module itself:
Hope it helps!
Comment #10
j.wick CreditAttribution: j.wick commentedFor non-developers:
Use the Views Field View module to imbed the relevant tax value on each line of a view table where each line represents one order. After enabling this module:
Now go into your the Orders view where you want to imbed the tax information:
Note: in order to use the token for Order ID, the Order ID field must be listed above the imbedded view field.
Comment #11
nicodv CreditAttribution: nicodv commentedThis module could help https://www.drupal.org/project/commerce_price_components
Comment #12
jsimonis CreditAttribution: jsimonis commentedSo there's really no way to create a custom report in Views where you can show how much someone paid for shipping and how much they paid for taxes?
Comment #13
hockey2112 CreditAttribution: hockey2112 commentedDoes anyone have a method that works for Drupal 8? I am attempting to create a CSV export of order data, and the tax amount needs to be included.
The commerce_price_components mentioned in #11 does not have a D8 version, and the Views Field Views solution in #10 doesn't work because there iis no View type called "Commerce Tax Information".
Comment #14
jsimonis CreditAttribution: jsimonis commentedI actually had to hire someone who created code for me to use in D7. This really should be standard since folks have to create tax reports.