Closed (fixed)
Project:
Commerce Reporting
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 May 2018 at 16:43 UTC
Updated:
19 May 2025 at 04:57 UTC
Jump to comment: Most recent, Most recent file


Comments
Comment #2
mglamanIn commerce_price.views.inc
The number field is marked to use the numeric field. When aggregating I am guessing that Views will default to the "first" field property as being the "real field", which is *_number. So on aggregation it sums to amount and it is rendering it using the numeric field handler.
Looks like we'll need to provide a custom handler.
Comment #3
mglamanIt might be more than that.
In \Drupal\views\Plugin\views\query\Sql::getAggregationInfo the aggregate options define the field handler.
Comment #4
mglamanOkay, so by picking any form of aggregate function it overrides the price field to be a Numeric handler and not even EntityField.
Comment #5
mglamanThere's no way to override the handler...easily.
In \Drupal\views\Plugin\views\display\DisplayPluginBase::getHandlers
The handler is overridden from that aggregation info. We would have to create a new display plugin which attempted to override this, using its own handler to support SUM on the field while GROUP on the currency code.
Comment #6
mglamanThis looks to be blocked, partially, by core #2975149: When using aggregation, additional fields should not be included in the grouping function
Comment #7
mglamanHere is a patch which implements the core patch fix to commerce_order_report views. It unsets aggregate functions to additional fields added in. Now we need to fix the formatting, which should be possible since we are grouping by the currency code, now.
Comment #8
mglamanOkay, it looks like we can't format the output in the pre_render Views hook. The \Drupal\views\Plugin\views\field\NumericField::render method calls
$value = round($value, $precision);which causes the formatter price to return0.Comment #9
mglamanThis makes it work! Swaps out the field handler later on.
Comment #11
mglamanWhoops, that had other cruft in it.
Comment #12
mglamanForgot I didn't make this dynamic and just hardcoded it for testing.
Comment #13
mglamanUsing an array_intersect we can check if there are matching additional fields and determine the price fields.
Comment #15
mglamanCommitted.
Comment #17
loze commentedI know this is very old but it looks like this is not working any longer.
I can t SUM on my price fields. Ive traced it back to commerce_reports_views_pre_build where this check here fails
The amount fields arent passing here so the custom formatter is never being used.
Comment #18
johazielHi,
I think issue need to be reopen,
$field_plugin is now intanceof EntityField (don't know why...)
I created createFromEntityField() based on createFromNumericField() and add test
The code is in the patch and now SUM work again and I can have my view of Tax reports working !
To be continue...
Comment #19
johazielSorry, some mistakes in the patch..
Comment #20
dlevchik commentedjohaziel, thanks for the patch. Unfortunately, it was not applying for 1.0.0-rc4 because you forgot ddl test output and commerce_reports.info.yml composer output.
I've updated your patch and now it applies for 1.0.0-rc4. I can confirm it works with AVG and SUM for my report views.
Comment #21
loze commentedThis doesn't quite solve the problem either.
The patch applies and I can add a field and aggregate on it, but when I go to edit the field, I get the following error:
Comment #22
loze commentedthe core patch here helps get this working for me #3344910: Ajax error on views with aggregation
Comment #23
johaziel@dlevchik Thanks for your correction, I was "speed" when I did it
@loze may be your view is to complicated, did you test with the base view_sales_report ?
My first goal was to create a taxes report view and also respond to #2976637: Create a taxes report
I put here my view, it works for me. Can you test with it.
You have to add in commerce_reports.links.menu.yml
Comment #24
tomtech commentedHi all,
Appreciate the feedback, but this issue was fixed 7 years ago.
If there is a regression or new problem, a new issue should be created, and optionally reference this one, if needed.
Based on the comments and patches, I suspect everyone encountering this issue now is using Drupal Core 10.4.6 or 11.1.6?
There was an issue in those releases that caused a problem with aggregate fields. (See: #2735997: Decimal separator and decimals settings ignored when aggregating decimal fields )
This issue was reverted in the following releases, 10.4.7 and 11.1.7. Upgrading to those version will likely resolve this regression.
If this doesn't resolve it, please open a new issue referencing this one.