Skip to content

Commit

Permalink
feat(core): Pass variant to ProductVariantPriceCalculationStrategy
Browse files Browse the repository at this point in the history
Closes #2398
  • Loading branch information
michaelbromley committed Sep 26, 2023
1 parent 1b29097 commit fee995c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';

import { roundMoney } from '../../common/round-money';
import { ProductVariant } from '../../entity/index';
import {
createRequestContext,
MockTaxRateService,
Expand All @@ -19,6 +20,7 @@ import { DefaultProductVariantPriceCalculationStrategy } from './default-product
describe('DefaultProductVariantPriceCalculationStrategy', () => {
let strategy: DefaultProductVariantPriceCalculationStrategy;
const inputPrice = 6543;
const productVariant = new ProductVariant({});

beforeAll(async () => {
await ensureConfigLoaded();
Expand All @@ -42,6 +44,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryStandard,
activeTaxZone: zoneDefault,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -57,6 +60,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryReduced,
activeTaxZone: zoneDefault,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -72,6 +76,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryStandard,
activeTaxZone: zoneOther,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -87,6 +92,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryReduced,
activeTaxZone: zoneOther,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -102,6 +108,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryReduced,
activeTaxZone: zoneWithNoTaxRate,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -119,6 +126,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryStandard,
activeTaxZone: zoneDefault,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -134,6 +142,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryReduced,
activeTaxZone: zoneDefault,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -149,6 +158,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryStandard,
activeTaxZone: zoneOther,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -164,6 +174,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryReduced,
activeTaxZone: zoneOther,
ctx,
productVariant,
});

expect(result).toEqual({
Expand All @@ -179,6 +190,7 @@ describe('DefaultProductVariantPriceCalculationStrategy', () => {
taxCategory: taxCategoryStandard,
activeTaxZone: zoneWithNoTaxRate,
ctx,
productVariant,
});

expect(result).toEqual({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RequestContext } from '../../api/common/request-context';
import { PriceCalculationResult } from '../../common/types/common-types';
import { InjectableStrategy } from '../../common/types/injectable-strategy';
import { ProductVariant } from '../../entity/product-variant/product-variant.entity';
import { TaxCategory } from '../../entity/tax-category/tax-category.entity';
import { Zone } from '../../entity/zone/zone.entity';

Expand All @@ -26,11 +27,14 @@ export interface ProductVariantPriceCalculationStrategy extends InjectableStrate
* @description
* The arguments passed the `calculate` method of the configured {@link ProductVariantPriceCalculationStrategy}.
*
* The `productVariant` argument was added in v2.1.0.
*
* @docsCategory products & stock
* @docsPage ProductVariantPriceCalculationStrategy
*/
export interface ProductVariantPriceCalculationArgs {
inputPrice: number;
productVariant: ProductVariant;
taxCategory: TaxCategory;
activeTaxZone: Zone;
ctx: RequestContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ProductPriceApplicator {
const { price, priceIncludesTax } = await productVariantPriceCalculationStrategy.calculate({
inputPrice: channelPrice.price,
taxCategory: variant.taxCategory,
productVariant: variant,
activeTaxZone,
ctx,
});
Expand Down

0 comments on commit fee995c

Please sign in to comment.