@haus-tech/campaign-price-plugin 1.0.2 → 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/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ ## 2.0.1
2
+
3
+ This was a version bump only for campaign-price-plugin to align it with other projects, there were no code changes.
4
+
5
+ # 2.0.0
6
+
7
+ This was a version bump only for campaign-price-plugin to align it with other projects, there were no code changes.
8
+
9
+ ## 1.1.0
10
+
11
+ ### 🚀 Features
12
+
13
+ - optimize price resolution in campaign price plugin ([706bc2e](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/706bc2e))
14
+ - add index file for campaign price plugin ([d0123d7](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/d0123d7))
15
+ - add campaign price plugin for Vendure ([e6579e9](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/e6579e9))
16
+
17
+ ### 🩹 Fixes
18
+
19
+ - handle channel and currencycode in campaign price plugin ([88f4362](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/88f4362))
20
+ - add TODO comment for tax support in campaign price label ([c6a7063](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/c6a7063))
21
+
22
+ ## 1.0.2
23
+
24
+ ### 🚀 Features
25
+
26
+ - optimize price resolution in campaign price plugin ([706bc2e](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/706bc2e))
27
+ - add index file for campaign price plugin ([d0123d7](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/d0123d7))
28
+ - add campaign price plugin for Vendure ([e6579e9](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/e6579e9))
29
+
30
+ ### 🩹 Fixes
31
+
32
+ - add TODO comment for tax support in campaign price label ([c6a7063](https://github.com/WeAreHausTech/haus-tech-vendure-plugins/commit/c6a7063))
33
+
1
34
  ## 1.0.1
2
35
 
3
36
  ### 🚀 Features
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: 1.0.0
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. When a campaign price is set, it is used as the selling price instead of the ordinary price. The plugin also exposes an `ordinaryPrice` field in the Shop API so storefronts can show “was X, now Y” pricing.
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
- - **Price calculation strategy** — If a variant has a campaign price set and it is greater than zero, that price is used; otherwise the existing price calculation strategy is used.
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. Restart your Vendure server.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/campaign-price-plugin",
3
- "version": "1.0.2",
3
+ "version": "3.0.0",
4
4
  "description": "Campaign price plugin",
5
5
  "author": "Haus Tech",
6
6
  "repository": "https://github.com/WeAreHausTech/haus-tech-vendure-plugins",
@@ -15,6 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CampaignPriceProductResolver = void 0;
16
16
  const graphql_1 = require("@nestjs/graphql");
17
17
  const core_1 = require("@vendure/core");
18
+ const helper_1 = require("../helpers/helper");
19
+ const get_campaign_price_for_channel_1 = require("../helpers/get-campaign-price-for-channel");
18
20
  let CampaignPriceProductResolver = class CampaignPriceProductResolver {
19
21
  productVariantService;
20
22
  constructor(productVariantService) {
@@ -46,12 +48,21 @@ let CampaignPriceProductResolver = class CampaignPriceProductResolver {
46
48
  // TODO: Cache the prices
47
49
  const prices = await Promise.all(product.variants.map(async (variant) => {
48
50
  if (!variant)
49
- return 0;
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
+ }
50
56
  const variantPrices = await this.productVariantService.getProductVariantPrices(ctx, variant.id);
51
- return variantPrices?.[0]?.price || 0;
57
+ const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variantPrices);
58
+ return activePrice?.price ?? 0;
52
59
  }));
53
- const min = Math.min(...prices);
54
- const max = Math.max(...prices);
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);
55
66
  return this.resolvePrice(min, max);
56
67
  }
57
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;AAI5E,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,EAA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rD,4BAA4B,CAmDxC"}
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,EAAE,YAAY;YACxB,GAAG;YACH,GAAG;SACJ,CAAA;IACH,CAAC;IAGK,AAAN,KAAK,CAAC,aAAa,CACV,GAAmB,EAChB,OAAgB;QAE1B,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAChC,CAAC;QAED,yBAAyB;QACzB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACrC,IAAI,CAAC,OAAO;gBAAE,OAAO,IAAI,CAAA;YAEzB,MAAM,aAAa,GAAG,IAAA,2DAA0B,EAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YAC9D,IAAI,aAAa,IAAI,IAAI,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;gBAChD,OAAO,IAAI,CAAA;YACb,CAAC;YAED,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,CAC5E,GAAG,EACH,OAAO,CAAC,EAAE,CACX,CAAA;YACD,MAAM,WAAW,GAAG,IAAA,iCAAwB,EAAC,GAAG,EAAE,aAAa,CAAC,CAAA;YAChE,OAAO,WAAW,EAAE,KAAK,IAAI,CAAC,CAAA;QAChC,CAAC,CAAC,CACH,CAAA;QAED,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAA;QACvF,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAChC,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,sBAAsB,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"}
@@ -15,21 +15,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CampaignPriceVariantResolver = void 0;
16
16
  const graphql_1 = require("@nestjs/graphql");
17
17
  const core_1 = require("@vendure/core");
18
+ const helper_1 = require("../helpers/helper");
18
19
  let CampaignPriceVariantResolver = class CampaignPriceVariantResolver {
19
20
  productVariantService;
20
21
  constructor(productVariantService) {
21
22
  this.productVariantService = productVariantService;
22
23
  }
23
24
  async ordinaryPrice(ctx, productVariant) {
24
- // Prefer using the already-loaded price on the ProductVariant, if available,
25
- // to avoid triggering an extra service call per variant (N+1 pattern).
26
- const directPrice = productVariant.price;
27
- if (typeof directPrice === 'number') {
28
- return directPrice;
29
- }
30
- // TODO: Cache the prices
31
25
  const variantPrices = await this.productVariantService.getProductVariantPrices(ctx, productVariant.id);
32
- return variantPrices[0]?.price || 0;
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
+ }
31
+ return activePrice?.price || 0;
33
32
  }
34
33
  };
35
34
  exports.CampaignPriceVariantResolver = CampaignPriceVariantResolver;
@@ -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;AAGnF,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,6EAA6E;QAC7E,uEAAuE;QACvE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAA;QACxC,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,OAAO,WAAW,CAAA;QACpB,CAAC;QAED,yBAAyB;QACzB,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,CAC5E,GAAG,EACH,cAAc,CAAC,EAAE,CAClB,CAAA;QAED,OAAO,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;IACrC,CAAC;CACF,CAAA;AAvBY,oEAA4B;AAIjC;IADL,IAAA,sBAAY,GAAE;IAEZ,WAAA,IAAA,UAAG,GAAE,CAAA;IACL,WAAA,IAAA,gBAAM,GAAE,CAAA;;qCADG,qBAAc;QACA,qBAAc;;iEAgBzC;uCAtBU,4BAA4B;IADxC,IAAA,kBAAQ,EAAC,gBAAgB,CAAC;qCAEkB,4BAAqB;GADrD,4BAA4B,CAuBxC"}
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");
@@ -36,10 +35,9 @@ exports.CampaignPricePlugin = CampaignPricePlugin = __decorate([
36
35
  ui: { component: 'currency-form-input' },
37
36
  label: [
38
37
  { languageCode: core_1.LanguageCode.en, value: 'Campaign Price' },
39
- { languageCode: core_1.LanguageCode.sv, value: 'Kampanjpris (inkl. moms)' }, // TODO: We need to support prices without tax?
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,gFAA0E;AAC1E,yDAAoD;AACpD,2FAAoF;AACpF,2FAAoF;AACpF,yFAAkF;AAgC3E,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAAG,CAAA;AAAtB,kDAAmB;8BAAnB,mBAAmB;IA9B/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,0BAA0B,EAAE,EAAE,+CAA+C;iBACtH;aACF,CAAC,CAAA;YAEF,MAAM,CAAC,cAAc,CAAC,sCAAsC,GAAG,IAAI,+CAAqB,CACtF,MAAM,CAAC,cAAc,CAAC,sCAAsC,CAC7D,CAAA;YAED,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAC;GACW,mBAAmB,CAAG"}
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"}
@@ -0,0 +1,7 @@
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 {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.campaignPriceCustomProductMappings = exports.campaignPriceIndexMappingProperties = void 0;
4
+ const helper_1 = require("../helpers/helper");
5
+ const get_campaign_price_for_channel_1 = require("../helpers/get-campaign-price-for-channel");
6
+ exports.campaignPriceIndexMappingProperties = {
7
+ 'product-ordinaryPriceMin': {
8
+ type: 'integer',
9
+ },
10
+ 'product-ordinaryPriceMax': {
11
+ type: 'integer',
12
+ },
13
+ };
14
+ exports.campaignPriceCustomProductMappings = {
15
+ ordinaryPriceMin: {
16
+ graphQlType: 'Int!',
17
+ valueFn: async (_product, productVariants, _languageCode, _injector, ctx) => {
18
+ if (!productVariants?.length) {
19
+ return 0;
20
+ }
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) => {
27
+ const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variant.productVariantPrices ?? []);
28
+ return activePrice?.price || 0;
29
+ });
30
+ if (!prices.length) {
31
+ return 0;
32
+ }
33
+ return Math.min(...prices);
34
+ },
35
+ },
36
+ ordinaryPriceMax: {
37
+ graphQlType: 'Int!',
38
+ valueFn: async (_product, productVariants, _languageCode, _injector, ctx) => {
39
+ if (!productVariants?.length) {
40
+ return 0;
41
+ }
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) => {
48
+ const activePrice = (0, helper_1.selectActiveVariantPrice)(ctx, variant.productVariantPrices ?? []);
49
+ return activePrice?.price || 0;
50
+ });
51
+ if (!prices.length) {
52
+ return 0;
53
+ }
54
+ return Math.max(...prices);
55
+ },
56
+ },
57
+ };
58
+ //# sourceMappingURL=campaign-price-elasticsearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"campaign-price-elasticsearch.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/elasticsearch/campaign-price-elasticsearch.ts"],"names":[],"mappings":";;;AAMA,8CAA4D;AAC5D,8FAAsF;AAEzE,QAAA,mCAAmC,GAE5C;IACF,0BAA0B,EAAE;QAC1B,IAAI,EAAE,SAAS;KAChB;IACD,0BAA0B,EAAE;QAC1B,IAAI,EAAE,SAAS;KAChB;CACF,CAAA;AAEY,QAAA,kCAAkC,GAE3C;IACF,gBAAgB,EAAE;QAChB,WAAW,EAAE,MAAM;QACnB,OAAO,EAAE,KAAK,E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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,2 @@
1
+ import { ProductVariant, RequestContext } from '@vendure/core';
2
+ export declare function getCampaignPriceForChannel(productVariant: ProductVariant, ctx: RequestContext): number | undefined;
@@ -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"}
@@ -0,0 +1,2 @@
1
+ import { RequestContext, ProductVariantPrice } from '@vendure/core';
2
+ export declare function selectActiveVariantPrice(ctx: RequestContext, variantPrices: ProductVariantPrice[]): ProductVariantPrice | undefined;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectActiveVariantPrice = selectActiveVariantPrice;
4
+ const core_1 = require("@vendure/core");
5
+ function selectActiveVariantPrice(ctx, variantPrices) {
6
+ const { channelId, currencyCode } = ctx;
7
+ return variantPrices.find((price) => (0, core_1.idsAreEqual)(price.channelId, channelId) && price.currencyCode === currencyCode);
8
+ }
9
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../packages/campaign-price-plugin/src/helpers/helper.ts"],"names":[],"mappings":";;AAGA,4DAQC;AAVD,wCAA2C;AAE3C,SAAgB,wBAAwB,CACtC,GAAmB,EACnB,aAAoC;IAEpC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,GAAG,CAAA;IACvC,OAAO,aAAa,CAAC,IAAI,CACvB,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,kBAAW,EAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,YAAY,CAC1F,CAAA;AACH,CAAC"}
package/src/index.d.ts CHANGED
@@ -1 +1,4 @@
1
1
  export * from './campaign-price.plugin';
2
+ export * from './elasticsearch/campaign-price-elasticsearch';
3
+ export * from './helpers/get-campaign-price-for-channel';
4
+ export * from './strategy/campaign-price.strategy';
package/src/index.js CHANGED
@@ -15,4 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./campaign-price.plugin"), exports);
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);
18
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"}
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,20 +11,20 @@ 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 get_campaign_price_for_channel_1 = require("../helpers/get-campaign-price-for-channel");
14
15
  let CampaignPriceStrategy = class CampaignPriceStrategy {
15
16
  existingStrategy;
16
17
  constructor(existingStrategy) {
17
18
  this.existingStrategy = existingStrategy;
18
19
  }
19
20
  async calculate(args) {
20
- const { productVariant } = args;
21
- const variantPrices = productVariant.productVariantPrices;
22
- const campaignPrice = variantPrices[0]?.customFields?.campaignPrice;
23
- if (campaignPrice != null && campaignPrice > 0) {
24
- return {
25
- price: campaignPrice,
26
- priceIncludesTax: true,
27
- };
21
+ const { productVariant, ctx } = args;
22
+ const campaignPriceForChannel = (0, get_campaign_price_for_channel_1.getCampaignPriceForChannel)(productVariant, ctx);
23
+ if (campaignPriceForChannel != null && campaignPriceForChannel > 0) {
24
+ return this.existingStrategy.calculate({
25
+ ...args,
26
+ inputPrice: campaignPriceForChannel,
27
+ });
28
28
  }
29
29
  return this.existingStrategy.calculate(args);
30
30
  }
@@ -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;AAcpC,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,IAAI,CAAA;QAE/B,MAAM,aAAa,GAAG,cAAc,CAAC,oBAAoB,CAAA;QACzD,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,aAAa,CAAA;QAEnE,IAAI,aAAa,IAAI,IAAI,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;YAC/C,OAAO;gBACL,KAAK,EAAE,aAAa;gBACpB,gBAAgB,EAAE,IAAI;aACvB,CAAA;QACH,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;CACF,CAAA;AAlBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;;GACA,qBAAqB,CAkBjC"}
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"}