Drupal Commerce is missing one important piece currently due to the way that price components are stored as serialized array: You can not use aggregate functions (SUM(), ... via GROUP BY) on price components.

Use case:

Try to create a table showing the summed up order amounts grouped by user: Total gross, VAT, net sum
=> Simply impossible!

Problem:

The handler doesn't take care of the aggregate function used in views and runs after the SQL based on the total amount result.

Comments

vincentdemers’s picture

mrpeanut’s picture

Have either of you found a solution for this issue? (I'm assuming not since this is still Active but wanted to check.)

vincentdemers’s picture

Hi! I ended up coding my own views custom field by implementing hook_views_handlers(). I used the group_concat mysql function to get a long string of all the entity_ids returned by the view. Then in my custom views field render function I did a entity_load for each entity to get the base_price of each order. I can share my code send me a private msg. good luck

anybody’s picture

@vincentdemers, it would be very helpful if you could paste your code here. Then no one has to disturb you and the code is available 24H and for further development.

Would be great, thank you! :)

vincentdemers’s picture

Hi @MrPeanut & @Anybody

Here is my custom views field handler as you have requested..