diff --git a/packages/vendure-plugin-metrics/CHANGELOG.md b/packages/vendure-plugin-metrics/CHANGELOG.md index 8414f5e0..05bd93d5 100644 --- a/packages/vendure-plugin-metrics/CHANGELOG.md +++ b/packages/vendure-plugin-metrics/CHANGELOG.md @@ -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) diff --git a/packages/vendure-plugin-metrics/src/api/metrics/sales-per-product.ts b/packages/vendure-plugin-metrics/src/api/metrics/units-sold-metric.ts similarity index 96% rename from packages/vendure-plugin-metrics/src/api/metrics/sales-per-product.ts rename to packages/vendure-plugin-metrics/src/api/metrics/units-sold-metric.ts index eff43588..7e36d9a8 100644 --- a/packages/vendure-plugin-metrics/src/api/metrics/sales-per-product.ts +++ b/packages/vendure-plugin-metrics/src/api/metrics/units-sold-metric.ts @@ -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 { +export class UnitsSoldMetric implements MetricStrategy { 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 { diff --git a/packages/vendure-plugin-metrics/src/metrics.plugin.ts b/packages/vendure-plugin-metrics/src/metrics.plugin.ts index 6b860c98..e685609d 100644 --- a/packages/vendure-plugin-metrics/src/metrics.plugin.ts +++ b/packages/vendure-plugin-metrics/src/metrics.plugin.ts @@ -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[]; @@ -31,7 +31,7 @@ export class MetricsPlugin { metrics: [ new RevenuePerProduct(), new AverageOrderValueMetric(), - new SalesPerProductMetric(), + new UnitsSoldMetric(), ], }; diff --git a/packages/vendure-plugin-metrics/test/metrics.spec.ts b/packages/vendure-plugin-metrics/test/metrics.spec.ts index 85dc467a..5f04ffa7 100644 --- a/packages/vendure-plugin-metrics/test/metrics.spec.ts +++ b/packages/vendure-plugin-metrics/test/metrics.spec.ts @@ -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); @@ -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);