@haus-tech/campaign-price-plugin 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -4
- package/package.json +1 -1
- package/src/api/campaign-price-product.resolver.js +13 -4
- package/src/api/campaign-price-product.resolver.js.map +1 -1
- package/src/api/campaign-price-variant.resolver.js +4 -0
- package/src/api/campaign-price-variant.resolver.js.map +1 -1
- package/src/campaign-price.plugin.js +0 -2
- package/src/campaign-price.plugin.js.map +1 -1
- package/src/elasticsearch/campaign-price-elasticsearch.d.ts +7 -3
- package/src/elasticsearch/campaign-price-elasticsearch.js +19 -2
- package/src/elasticsearch/campaign-price-elasticsearch.js.map +1 -1
- package/src/helpers/get-campaign-price-for-channel.d.ts +2 -0
- package/src/helpers/get-campaign-price-for-channel.js +9 -0
- package/src/helpers/get-campaign-price-for-channel.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/strategy/campaign-price.strategy.js +2 -3
- package/src/strategy/campaign-price.strategy.js.map +1 -1
package/README.md
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
name: campaign-price-plugin
|
|
3
3
|
title: Campaign Price Plugin
|
|
4
4
|
description: Vendure plugin that adds campaign pricing with an ordinaryPrice field for "was / now" display.
|
|
5
|
-
version:
|
|
5
|
+
version: 2.0.0
|
|
6
6
|
tags: [vendure, plugin, campaign, price, sale]
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# Campaign Price Plugin
|
|
10
10
|
|
|
11
|
-
The **Campaign Price Plugin** is a Vendure plugin that lets you run campaigns and sales by setting a campaign price on product variant prices.
|
|
11
|
+
The **Campaign Price Plugin** is a Vendure plugin that lets you run campaigns and sales by setting a campaign price on product variant prices. The plugin exposes helpers to compose campaign pricing into your own price strategy, and adds an `ordinaryPrice` field in the Shop API so storefronts can show “was X, now Y” pricing.
|
|
12
12
|
|
|
13
13
|
## Functionality
|
|
14
14
|
|
|
15
15
|
- **Campaign price custom field** — Add a `campaignPrice` (integer) to `ProductVariantPrice`, editable per channel/currency in the Admin UI.
|
|
16
|
-
- **
|
|
16
|
+
- **Campaign helper + strategy export** — Use `getCampaignPriceForChannel()` and `CampaignPriceStrategy` to compose campaign pricing in your project strategy setup.
|
|
17
17
|
- **Ordinary price in Shop API** — `ProductVariant`, `Product`, and `SearchResult` get an `ordinaryPrice` field so the storefront can display the original price alongside the current (possibly campaign) price.
|
|
18
18
|
|
|
19
19
|
## Use Cases
|
|
@@ -48,10 +48,44 @@ To install the `Campaign Price Plugin`, follow these steps:
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
3.
|
|
51
|
+
3. Compose your `productVariantPriceCalculationStrategy` in your project (recommended when combining campaign price with other strategies like price lists), or use the function`getCampaignPriceForChannel` in your own custom `ProductVariantPriceCalculationStrategy`:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { PluginCommonModule, VendurePlugin } from '@vendure/core'
|
|
55
|
+
import { CampaignPricePlugin, CampaignPriceStrategy } from '@haus-tech/campaign-price-plugin'
|
|
56
|
+
import { PriceListProductVariantPriceCalculationStrategy } from './plugins/price-list/strategy/price-list-product-variant-price-calculation.strategy'
|
|
57
|
+
|
|
58
|
+
@VendurePlugin({
|
|
59
|
+
imports: [PluginCommonModule],
|
|
60
|
+
configuration: (config) => {
|
|
61
|
+
config.catalogOptions.productVariantPriceCalculationStrategy =
|
|
62
|
+
new PriceListProductVariantPriceCalculationStrategy(
|
|
63
|
+
new CampaignPriceStrategy(config.catalogOptions.productVariantPriceCalculationStrategy),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return config
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
export class PricingCompositionPlugin {}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
4. Restart your Vendure server.
|
|
52
73
|
|
|
53
74
|
## Usage
|
|
54
75
|
|
|
76
|
+
### Price strategy composition
|
|
77
|
+
|
|
78
|
+
`CampaignPricePlugin` no longer overrides `config.catalogOptions.productVariantPriceCalculationStrategy` automatically.
|
|
79
|
+
This is intentional so projects can control precedence between campaign pricing and other pricing strategies.
|
|
80
|
+
|
|
81
|
+
You can use the helper directly in your own custom strategy:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { getCampaignPriceForChannel } from '@haus-tech/campaign-price-plugin'
|
|
85
|
+
|
|
86
|
+
const campaignPrice = getCampaignPriceForChannel(args.productVariant, args.ctx)
|
|
87
|
+
```
|
|
88
|
+
|
|
55
89
|
### Admin UI
|
|
56
90
|
|
|
57
91
|
In the Admin UI, each product variant price has a **Campaign Price** field (per channel/currency). Set it to run a campaign; leave it empty or zero to use the ordinary price. The field uses the currency form input component.
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ exports.CampaignPriceProductResolver = void 0;
|
|
|
16
16
|
const graphql_1 = require("@nestjs/graphql");
|
|
17
17
|
const core_1 = require("@vendure/core");
|
|
18
18
|
const helper_1 = require("../helpers/helper");
|
|
19
|
+
const get_campaign_price_for_channel_1 = require("../helpers/get-campaign-price-for-channel");
|
|
19
20
|
let CampaignPriceProductResolver = class CampaignPriceProductResolver {
|
|
20
21
|
productVariantService;
|
|
21
22
|
constructor(productVariantService) {
|
|
@@ -47,13 +48,21 @@ let CampaignPriceProductResolver = class CampaignPriceProductResolver {
|
|
|
47
48
|
// TODO: Cache the prices
|
|
48
49
|
const prices = await Promise.all(product.variants.map(async (variant) => {
|
|
49
50
|
if (!variant)
|
|
50
|
-
return
|
|
51
|
+
return null;
|
|
52
|
+
const campaignPrice = (0, get_campaign_price_for_channel_1.getCampaignPriceForChannel)(variant, ctx);
|
|
53
|
+
if (campaignPrice == null || campaignPrice <= 0) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
51
56
|
const variantPrices = await this.productVariantService.getProductVariantPrices(ctx, variant.id);
|
|
52
57
|
const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variantPrices);
|
|
53
|
-
return activePrice?.price
|
|
58
|
+
return activePrice?.price ?? 0;
|
|
54
59
|
}));
|
|
55
|
-
const
|
|
56
|
-
|
|
60
|
+
const campaignOrdinaryPrices = prices.filter((price) => price != null);
|
|
61
|
+
if (!campaignOrdinaryPrices.length) {
|
|
62
|
+
return this.resolvePrice(0, 0);
|
|
63
|
+
}
|
|
64
|
+
const min = Math.min(...campaignOrdinaryPrices);
|
|
65
|
+
const max = Math.max(...campaignOrdinaryPrices);
|
|
57
66
|
return this.resolvePrice(min, max);
|
|
58
67
|
}
|
|
59
68
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaign-price-product.resolver.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/api/campaign-price-product.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAgE;AAChE,wCAAmF;AAEnF,8CAA4D;
|
|
1
|
+
{"version":3,"file":"campaign-price-product.resolver.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/api/campaign-price-product.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAgE;AAChE,wCAAmF;AAEnF,8CAA4D;AAC5D,8FAAsF;AAG/E,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACnB;IAApB,YAAoB,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;IAAG,CAAC;IAE5D,YAAY,CAAC,GAAY,EAAE,GAAY;QAC7C,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YAC3C,OAAO;gBACL,UAAU,EAAE,aAAa;gBACzB,KAAK,EAAE,CAAC;aACT,CAAA;QACH,CAAC;QAED,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;YAChB,OAAO;gBACL,UAAU,EAAE,aAAa;gBACzB,KAAK,EAAE,GAAG;aACX,CAAA;QACH,CAAC;QAED,OAAO;YACL,UAAU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CAAC,CAAA;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,CAAA;QAE/C,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACpC,CAAC;CACF,CAAA;AA/DY,oEAA4B;AA0BjC;IADL,IAAA,sBAAY,EAAC,eAAe,CAAC;IAE3B,WAAA,IAAA,UAAG,GAAE,CAAA;IACL,WAAA,IAAA,gBAAM,GAAE,CAAA;;qCADG,qBAAc;QACP,cAAO;;iEAkC3B;uCA9DU,4BAA4B;IADxC,IAAA,kBAAQ,EAAC,SAAS,CAAC;qCAEyB,4BAAqB;GADrD,4BAA4B,CA+DxC"}
|
|
@@ -24,6 +24,10 @@ let CampaignPriceVariantResolver = class CampaignPriceVariantResolver {
|
|
|
24
24
|
async ordinaryPrice(ctx, productVariant) {
|
|
25
25
|
const variantPrices = await this.productVariantService.getProductVariantPrices(ctx, productVariant.id);
|
|
26
26
|
const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variantPrices);
|
|
27
|
+
const isOnCampaign = activePrice?.customFields?.campaignPrice && activePrice?.customFields?.campaignPrice > 0;
|
|
28
|
+
if (!isOnCampaign) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
27
31
|
return activePrice?.price || 0;
|
|
28
32
|
}
|
|
29
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaign-price-variant.resolver.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/api/campaign-price-variant.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAgE;AAChE,wCAA0F;AAC1F,8CAA4D;AAGrD,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACnB;IAApB,YAAoB,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;IAAG,CAAC;IAG9D,AAAN,KAAK,CAAC,aAAa,CACV,GAAmB,EAChB,cAA8B;QAExC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,CAC5E,GAAG,EACH,cAAc,CAAC,EAAE,CAClB,CAAA;
|
|
1
|
+
{"version":3,"file":"campaign-price-variant.resolver.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/api/campaign-price-variant.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAgE;AAChE,wCAA0F;AAC1F,8CAA4D;AAGrD,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACnB;IAApB,YAAoB,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;IAAG,CAAC;IAG9D,AAAN,KAAK,CAAC,aAAa,CACV,GAAmB,EAChB,cAA8B;QAExC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,CAC5E,GAAG,EACH,cAAc,CAAC,EAAE,CAClB,CAAA;QAED,MAAM,WAAW,GAAG,IAAA,iCAAwB,EAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QAEhE,MAAM,YAAY,GAChB,WAAW,EAAE,YAAY,EAAE,aAAa,IAAI,WAAW,EAAE,YAAY,EAAE,aAAa,GAAG,CAAC,CAAA;QAE1F,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,CAAA;QACV,CAAC;QAED,OAAO,WAAW,EAAE,KAAK,IAAI,CAAC,CAAA;IAChC,CAAC;CACF,CAAA;AAxBY,oEAA4B;AAIjC;IADL,IAAA,sBAAY,GAAE;IAEZ,WAAA,IAAA,UAAG,GAAE,CAAA;IACL,WAAA,IAAA,gBAAM,GAAE,CAAA;;qCADG,qBAAc;QACA,qBAAc;;iEAiBzC;uCAvBU,4BAA4B;IADxC,IAAA,kBAAQ,EAAC,gBAAgB,CAAC;qCAEkB,4BAAqB;GADrD,4BAA4B,CAwBxC"}
|
|
@@ -8,7 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.CampaignPricePlugin = void 0;
|
|
10
10
|
const core_1 = require("@vendure/core");
|
|
11
|
-
const campaign_price_strategy_1 = require("./strategy/campaign-price.strategy");
|
|
12
11
|
const api_extensions_1 = require("./api/api-extensions");
|
|
13
12
|
const campaign_price_variant_resolver_1 = require("./api/campaign-price-variant.resolver");
|
|
14
13
|
const campaign_price_product_resolver_1 = require("./api/campaign-price-product.resolver");
|
|
@@ -39,7 +38,6 @@ exports.CampaignPricePlugin = CampaignPricePlugin = __decorate([
|
|
|
39
38
|
{ languageCode: core_1.LanguageCode.sv, value: 'Kampanjpris' },
|
|
40
39
|
],
|
|
41
40
|
});
|
|
42
|
-
config.catalogOptions.productVariantPriceCalculationStrategy = new campaign_price_strategy_1.CampaignPriceStrategy(config.catalogOptions.productVariantPriceCalculationStrategy);
|
|
43
41
|
return config;
|
|
44
42
|
},
|
|
45
43
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaign-price.plugin.js","sourceRoot":"","sources":["../../../../packages/campaign-price-plugin/src/campaign-price.plugin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wCAA+E;AAC/E,
|
|
1
|
+
{"version":3,"file":"campaign-price.plugin.js","sourceRoot":"","sources":["../../../../packages/campaign-price-plugin/src/campaign-price.plugin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wCAA+E;AAC/E,yDAAoD;AACpD,2FAAoF;AACpF,2FAAoF;AACpF,yFAAkF;AA4B3E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAAG,CAAA;AAAtB,kDAAmB;8BAAnB,mBAAmB;IA1B/B,IAAA,oBAAa,EAAC;QACb,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,iBAAiB,EAAE;YACjB,MAAM,EAAE,8BAAa;YACrB,SAAS,EAAE;gBACT,8DAA4B;gBAC5B,8DAA4B;gBAC5B,4DAA2B;aAC5B;SACF;QACD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;YACxB,MAAM,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC;gBAC3C,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,KAAK;gBACX,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,IAAI;gBACZ,EAAE,EAAE,EAAE,SAAS,EAAE,qBAAqB,EAAE;gBACxC,KAAK,EAAE;oBACL,EAAE,YAAY,EAAE,mBAAY,CAAC,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;oBAC1D,EAAE,YAAY,EAAE,mBAAY,CAAC,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE;iBACxD;aACF,CAAC,CAAA;YAEF,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAC;GACW,mBAAmB,CAAG"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type ElasticsearchOptionsLike = {
|
|
2
|
+
indexMappingProperties?: Record<string, unknown>;
|
|
3
|
+
customProductMappings?: Record<string, unknown>;
|
|
4
|
+
};
|
|
5
|
+
export declare const campaignPriceIndexMappingProperties: NonNullable<ElasticsearchOptionsLike['indexMappingProperties']>;
|
|
6
|
+
export declare const campaignPriceCustomProductMappings: NonNullable<ElasticsearchOptionsLike['customProductMappings']>;
|
|
7
|
+
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.campaignPriceCustomProductMappings = exports.campaignPriceIndexMappingProperties = void 0;
|
|
4
4
|
const helper_1 = require("../helpers/helper");
|
|
5
|
+
const get_campaign_price_for_channel_1 = require("../helpers/get-campaign-price-for-channel");
|
|
5
6
|
exports.campaignPriceIndexMappingProperties = {
|
|
6
7
|
'product-ordinaryPriceMin': {
|
|
7
8
|
type: 'integer',
|
|
@@ -17,10 +18,18 @@ exports.campaignPriceCustomProductMappings = {
|
|
|
17
18
|
if (!productVariants?.length) {
|
|
18
19
|
return 0;
|
|
19
20
|
}
|
|
20
|
-
const prices = productVariants
|
|
21
|
+
const prices = productVariants
|
|
22
|
+
.filter((variant) => {
|
|
23
|
+
const campaignPrice = (0, get_campaign_price_for_channel_1.getCampaignPriceForChannel)(variant, ctx);
|
|
24
|
+
return campaignPrice != null && campaignPrice > 0;
|
|
25
|
+
})
|
|
26
|
+
.map((variant) => {
|
|
21
27
|
const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variant.productVariantPrices ?? []);
|
|
22
28
|
return activePrice?.price || 0;
|
|
23
29
|
});
|
|
30
|
+
if (!prices.length) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
24
33
|
return Math.min(...prices);
|
|
25
34
|
},
|
|
26
35
|
},
|
|
@@ -30,10 +39,18 @@ exports.campaignPriceCustomProductMappings = {
|
|
|
30
39
|
if (!productVariants?.length) {
|
|
31
40
|
return 0;
|
|
32
41
|
}
|
|
33
|
-
const prices = productVariants
|
|
42
|
+
const prices = productVariants
|
|
43
|
+
.filter((variant) => {
|
|
44
|
+
const campaignPrice = (0, get_campaign_price_for_channel_1.getCampaignPriceForChannel)(variant, ctx);
|
|
45
|
+
return campaignPrice != null && campaignPrice > 0;
|
|
46
|
+
})
|
|
47
|
+
.map((variant) => {
|
|
34
48
|
const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variant.productVariantPrices ?? []);
|
|
35
49
|
return activePrice?.price || 0;
|
|
36
50
|
});
|
|
51
|
+
if (!prices.length) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
37
54
|
return Math.max(...prices);
|
|
38
55
|
},
|
|
39
56
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaign-price-elasticsearch.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/elasticsearch/campaign-price-elasticsearch.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"campaign-price-elasticsearch.js","sourceRoot":"","sources":["../../../../../packages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,EACnB,EAAE;YACF,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC;gBAC7B,OAAO,CAAC,CAAA;YACV,CAAC;YAED,MAAM,MAAM,GAAG,eAAe;iBAC3B,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;gBAClB,MAAM,aAAa,GAAG,IAAA,2DAA0B,EAAC,OAAO,EAAE,GAAG,CAAC,CAAA;gBAC9D,OAAO,aAAa,IAAI,IAAI,IAAI,aAAa,GAAG,CAAC,CAAA;YACnD,CAAC,CAAC;iBACD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;gBACf,MAAM,WAAW,GAAG,IAAA,iCAAwB,EAAC,GAAG,EAAE,OAAO,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAA;gBACrF,OAAO,WAAW,EAAE,KAAK,IAAI,CAAC,CAAA;YAChC,CAAC,CAAC,CAAA;YAEJ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBACnB,OAAO,CAAC,CAAA;YACV,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAA;QAC5B,CAAC;KACF;CACF,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCampaignPriceForChannel = getCampaignPriceForChannel;
|
|
4
|
+
const core_1 = require("@vendure/core");
|
|
5
|
+
function getCampaignPriceForChannel(productVariant, ctx) {
|
|
6
|
+
const { currencyCode, channelId } = ctx;
|
|
7
|
+
return productVariant.productVariantPrices.find((price) => (0, core_1.idsAreEqual)(price.channelId, channelId) && price.currencyCode === currencyCode)?.customFields?.campaignPrice;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=get-campaign-price-for-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-campaign-price-for-channel.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/helpers/get-campaign-price-for-channel.ts"],"names":[],"mappings":";;AAEA,gEASC;AAXD,wCAA2E;AAE3E,SAAgB,0BAA0B,CACxC,cAA8B,EAC9B,GAAmB;IAEnB,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,GAAG,CAAA;IAEvC,OAAO,cAAc,CAAC,oBAAoB,CAAC,IAAI,CAC7C,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,kBAAW,EAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,YAAY,CAC1F,EAAE,YAAY,EAAE,aAAa,CAAA;AAChC,CAAC"}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -16,4 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./campaign-price.plugin"), exports);
|
|
18
18
|
__exportStar(require("./elasticsearch/campaign-price-elasticsearch"), exports);
|
|
19
|
+
__exportStar(require("./helpers/get-campaign-price-for-channel"), exports);
|
|
20
|
+
__exportStar(require("./strategy/campaign-price.strategy"), exports);
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/campaign-price-plugin/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,+EAA4D"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/campaign-price-plugin/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,+EAA4D;AAC5D,2EAAwD;AACxD,qEAAkD"}
|
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CampaignPriceStrategy = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
|
-
const
|
|
14
|
+
const get_campaign_price_for_channel_1 = require("../helpers/get-campaign-price-for-channel");
|
|
15
15
|
let CampaignPriceStrategy = class CampaignPriceStrategy {
|
|
16
16
|
existingStrategy;
|
|
17
17
|
constructor(existingStrategy) {
|
|
@@ -19,8 +19,7 @@ let CampaignPriceStrategy = class CampaignPriceStrategy {
|
|
|
19
19
|
}
|
|
20
20
|
async calculate(args) {
|
|
21
21
|
const { productVariant, ctx } = args;
|
|
22
|
-
const
|
|
23
|
-
const campaignPriceForChannel = productVariant.productVariantPrices.find((price) => (0, core_1.idsAreEqual)(price.channelId, channelId) && price.currencyCode === currencyCode)?.customFields?.campaignPrice;
|
|
22
|
+
const campaignPriceForChannel = (0, get_campaign_price_for_channel_1.getCampaignPriceForChannel)(productVariant, ctx);
|
|
24
23
|
if (campaignPriceForChannel != null && campaignPriceForChannel > 0) {
|
|
25
24
|
return this.existingStrategy.calculate({
|
|
26
25
|
...args,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaign-price.strategy.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/strategy/campaign-price.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2C;
|
|
1
|
+
{"version":3,"file":"campaign-price.strategy.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/strategy/campaign-price.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2C;AAM3C,8FAAsF;AAS/E,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACZ;IAApB,YAAoB,gBAAwD;QAAxD,qBAAgB,GAAhB,gBAAgB,CAAwC;IAAG,CAAC;IAEhF,KAAK,CAAC,SAAS,CAAC,IAAwC;QACtD,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;QACpC,MAAM,uBAAuB,GAAG,IAAA,2DAA0B,EAAC,cAAc,EAAE,GAAG,CAAC,CAAA;QAE/E,IAAI,uBAAuB,IAAI,IAAI,IAAI,uBAAuB,GAAG,CAAC,EAAE,CAAC;YACnE,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC;gBACrC,GAAG,IAAI;gBACP,UAAU,EAAE,uBAAuB;aACpC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;CACF,CAAA;AAhBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;;GACA,qBAAqB,CAgBjC"}
|