A small Drupal Commerce module with a service for order statistics, written as a test assignment in March 2022.
The orders_assistant service works with completed orders in a date range:
| Method | Returns |
|---|---|
getOrdersNumber($from, $to) |
Number of completed orders |
getAverageOrderValue($from, $to, $currency_code = 'USD', $uid = '') |
Average order value, optionally for one customer |
getMostPurchasedEntity($from, $to) |
The product variation with the most units sold |
use Drupal\Core\Datetime\DrupalDateTime;
$assistant = \Drupal::service('orders_assistant');
$from = new DrupalDateTime('first day of last month 00:00');
$to = new DrupalDateTime('last day of last month 23:59');
$count = $assistant->getOrdersNumber($from, $to);
$average = $assistant->getAverageOrderValue($from, $to, 'USD');
$topProduct = $assistant->getMostPurchasedEntity($from, $to);Drupal 8 or 9 with Drupal Commerce (order and product modules).
git clone https://github.com/dimidjy/orders_assistant.git web/modules/custom/orders_assistant
drush en orders_assistant