Price fields do not work properly when using SUM/AVG aggregation functions

Created on 24 May 2018, about 7 years ago
Updated 1 May 2025, about 1 month ago

When using "group results", price fields render correctly if the group column if Number and additionally the Currency Code field is selected.

However, choosing SUM or AVG causes the price field to render as a normal integer field.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    I 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

      if ($field_plugin instanceof NumericField) {
    

    The amount fields arent passing here so the custom formatter is never being used.

  • πŸ‡«πŸ‡·France johaziel

    Hi,
    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

    if ($field_plugin instanceof EntityField) { ...
    ...PriceNumericField::createFromEntityField($field_plugin)..
    }
    

    The code is in the patch and now SUM work again and I can have my view of Tax reports working !

    To be continue...

  • πŸ‡«πŸ‡·France johaziel

    Sorry, some mistakes in the patch..

  • πŸ‡΅πŸ‡±Poland dlevchik Poznan, Poland

    johaziel, 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.

  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    This doesnt quire solve the problem either.

    I can add a field and aggrigate on it, but when I go to edit a field I get the following error:

    "
    An AJAX HTTP error occurred.
    HTTP Result Code: 500
    Debugging information follows.
    Path: /admin/structure/views/ajax/handler-group/sales_report/block_1/field/amount_2
    StatusText: 500 Service unavailable (with message)
    ResponseText: The website encountered an unexpected error. Try again later.TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 727 of core/modules/views/src/Plugin/views/field/EntityField.php). Drupal\views\Plugin\views\field\EntityField->submitGroupByForm(Array, Object) (Line: 106)
    Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 268)
    Drupal\views_ui\ViewUI->standardSubmit(Array, Object)
    call_user_func_array(Array, Array) (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('views_ui_config_item_group_form', Array, Object) (Line: 326)
    Drupal\Core\Form\FormBuilder->buildForm('Drupal\views_ui\Form\Ajax\ConfigHandlerGroup', Object) (Line: 215)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 217)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper('Drupal\views_ui\Form\Ajax\ConfigHandlerGroup', Object) (Line: 127)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object, 'block_1', 'ajax') (Line: 38)
    Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->getForm(Object, 'block_1', 'ajax', 'field', 'amount_2')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    "
    
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    the core patch here helps get this working for me πŸ› Ajax error on views with aggregation. Active

  • πŸ‡«πŸ‡·France 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 ✨ Create a taxes report Active

    I put here my view, it works for me. Can you test with it.
    You have to add in commerce_reports.links.menu.yml

    commerce_reports.taxes_report:
      title: 'Taxes'
      route_name: 'view.taxes_report.monthly'
      parent: 'commerce_reports.overview'
  • πŸ‡ΊπŸ‡ΈUnited States TomTech

    Hi 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: πŸ› Decimal separator and decimals settings ignored when aggregating decimal fields Needs work )

    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.

Production build 0.71.5 2024