Skip to content

Commit

Permalink
feat(metrics): units sold instead of salesper product
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug committed Oct 31, 2024
1 parent d4f794c commit bca39a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/vendure-plugin-metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Added revenue (per variant) metric
- Calculate with or without tax based on channel settings
- Use number instead of currency formatting for Sales-per-product metric
- Use number instead of currency formatting for Units Sold metric
- Added a max cache age of 12 hours for metrics

# 1.3.2 (2024-10-29)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { loggerCtx } from '../../constants';
* Calculates the number of products sold per month.
* calculates the sum of all items in an order if no variantIds are provided
*/
export class SalesPerProductMetric implements MetricStrategy<OrderLine> {
export class UnitsSoldMetric implements MetricStrategy<OrderLine> {
readonly metricType: AdvancedMetricType = AdvancedMetricType.Number;
readonly code = 'sales-per-product';
readonly code = 'units-sold';

getTitle(ctx: RequestContext): string {
return `Sales`;
return `Units sold`;
}

getSortableField(entity: OrderLine): Date {
Expand Down
4 changes: 2 additions & 2 deletions packages/vendure-plugin-metrics/src/metrics.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MetricStrategy } from './api/metric-strategy';
import { PLUGIN_INIT_OPTIONS } from './constants';
import { RevenuePerProduct } from './api/metrics/revenue-per-product';
import { AverageOrderValueMetric } from './api/metrics/average-order-value';
import { SalesPerProductMetric } from './api/metrics/sales-per-product';
import { UnitsSoldMetric } from './api/metrics/units-sold-metric';

export interface MetricsPluginOptions {
metrics: MetricStrategy<any>[];
Expand All @@ -31,7 +31,7 @@ export class MetricsPlugin {
metrics: [
new RevenuePerProduct(),
new AverageOrderValueMetric(),
new SalesPerProductMetric(),
new UnitsSoldMetric(),
],
};

Expand Down
4 changes: 2 additions & 2 deletions packages/vendure-plugin-metrics/test/metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Metrics', () => {
(m) => m.code === 'revenue-per-product'
)!;
const salesPerProduct = advancedMetricSummaries.find(
(m) => m.code === 'sales-per-product'
(m) => m.code === 'units-sold'
)!;
expect(advancedMetricSummaries.length).toEqual(3);
expect(averageOrderValue.series[0].values.length).toEqual(13);
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('Metrics', () => {
// Expect the first series (variant 2), to have 839400 revenue in last month
expect(revenuePerProduct.series[1].values[12]).toEqual(8394);
const salesPerProduct = advancedMetricSummaries.find(
(m) => m.code === 'sales-per-product'
(m) => m.code === 'units-sold'
)!;
// For sales per product we expect 2 series: one for each variant
expect(salesPerProduct.series[0].values.length).toEqual(13);
Expand Down

0 comments on commit bca39a0

Please sign in to comment.