Add some examples how to query the reports programmatically

Created on 13 November 2024, about 1 month ago

Problem/Motivation

Hi and thank you so much for this wonderful module.

The module page points out, that this is more or less a developer module (plus views), but I can't find a good way to start, for query'ing the reports, for example through EntityQuery?

Is there a good place to find examples already and could some basic examples be added to the README perhaps?

That would be super helpful!

Thank you very much in advance!

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    This might be a very simple starting point, based on some tests I found:

        /** @var \Drupal\commerce_reports\ReportTypeManager $reportTypeManager */
        $reportTypeManager = \Drupal::service('plugin.manager.commerce_report_type');
        /** @var \Drupal\commerce_reports\ReportQueryBuilder $reportQueryBuilder */
        $reportQueryBuilder = \Drupal::service('commerce_reports.query_builder');
        /** @var \Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeInterface $report_type_plugin */
        $orderReportPlugin = $reportTypeManager->createInstance('order_report');
    
        $query = $reportQueryBuilder->getQuery($orderReportPlugin);
        $query->accessCheck(TRUE)
          ->range(0, 50)
          ->sort('quantity', 'DESC');
    
        $results = $query->execute();
    
Production build 0.71.5 2024