Skip to content

About

Test assignment: Drupal Commerce service for order statistics (count, average value, top product)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

orders_assistant

A small Drupal Commerce module with a service for order statistics, written as a test assignment in March 2022.

What it does

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

Usage

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);

Requirements

Drupal 8 or 9 with Drupal Commerce (order and product modules).

Installation

git clone https://github.com/dimidjy/orders_assistant.git web/modules/custom/orders_assistant
drush en orders_assistant

About

Test assignment: Drupal Commerce service for order statistics (count, average value, top product)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages