-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add ProductVariantPriceSelectionStrategy
Relates to #1691 This adds a new configurable strategy which allows you to define the logic by which a variant price is selected based on factors like active channel and currency code.
- Loading branch information
1 parent
24e558b
commit efe23d1
Showing
7 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/core/src/config/catalog/default-product-variant-price-selection-strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { RequestContext } from '../../api/common/request-context'; | ||
import { idsAreEqual } from '../../common/utils'; | ||
import { ProductVariantPrice } from '../../entity/product-variant/product-variant-price.entity'; | ||
|
||
import { ProductVariantPriceSelectionStrategy } from './product-variant-price-selection-strategy'; | ||
|
||
/** | ||
* @description | ||
* The default strategy for selecting the price for a ProductVariant in a given Channel. | ||
*/ | ||
export class DefaultProductVariantPriceSelectionStrategy implements ProductVariantPriceSelectionStrategy { | ||
selectPrice(ctx: RequestContext, prices: ProductVariantPrice[]) { | ||
return prices.find(p => idsAreEqual(p.channelId, ctx.channelId)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/core/src/config/catalog/product-variant-price-selection-strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RequestContext } from '../../api/common/request-context'; | ||
import { InjectableStrategy } from '../../common/types/injectable-strategy'; | ||
import { ProductVariantPrice } from '../../entity/product-variant/product-variant-price.entity'; | ||
|
||
export interface ProductVariantPriceSelectionStrategy extends InjectableStrategy { | ||
selectPrice( | ||
ctx: RequestContext, | ||
prices: ProductVariantPrice[], | ||
): ProductVariantPrice | undefined | Promise<ProductVariantPrice | undefined>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters