@medusajs/pricing 0.1.13-preview-20240704133323 → 0.1.13-preview-20240704145232

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,5 +9,6 @@ exports.joinerConfig = (0, utils_1.defineJoinerConfig)(utils_1.Modules.PRICING,
9
9
  price_set_id: _models_1.PriceSet.name,
10
10
  price_list_id: _models_1.PriceList.name,
11
11
  price_id: _models_1.Price.name,
12
+ price_preference_id: _models_1.PricePreference.name,
12
13
  },
13
14
  });
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ export declare class Migration20240704094505 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20240704094505 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20240704094505 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql('create table if not exists "price_preference" ("id" text not null, "attribute" text not null, "value" text null, "is_tax_inclusive" boolean not null default false, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_preference_pkey" primary key ("id"));');
8
+ this.addSql('CREATE INDEX IF NOT EXISTS "IDX_price_preference_deleted_at" ON "price_preference" (deleted_at) WHERE deleted_at IS NOT NULL;');
9
+ this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_preference_attribute_value" ON "price_preference" (attribute, value) WHERE deleted_at IS NULL;');
10
+ }
11
+ async down() {
12
+ this.addSql('drop table if exists "price_preference" cascade;');
13
+ }
14
+ }
15
+ exports.Migration20240704094505 = Migration20240704094505;
@@ -3,3 +3,4 @@ export { default as PriceList } from "./price-list";
3
3
  export { default as PriceListRule } from "./price-list-rule";
4
4
  export { default as PriceRule } from "./price-rule";
5
5
  export { default as PriceSet } from "./price-set";
6
+ export { default as PricePreference } from "./price-preference";
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PriceSet = exports.PriceRule = exports.PriceListRule = exports.PriceList = exports.Price = void 0;
6
+ exports.PricePreference = exports.PriceSet = exports.PriceRule = exports.PriceListRule = exports.PriceList = exports.Price = void 0;
7
7
  var price_1 = require("./price");
8
8
  Object.defineProperty(exports, "Price", { enumerable: true, get: function () { return __importDefault(price_1).default; } });
9
9
  var price_list_1 = require("./price-list");
@@ -14,3 +14,5 @@ var price_rule_1 = require("./price-rule");
14
14
  Object.defineProperty(exports, "PriceRule", { enumerable: true, get: function () { return __importDefault(price_rule_1).default; } });
15
15
  var price_set_1 = require("./price-set");
16
16
  Object.defineProperty(exports, "PriceSet", { enumerable: true, get: function () { return __importDefault(price_set_1).default; } });
17
+ var price_preference_1 = require("./price-preference");
18
+ Object.defineProperty(exports, "PricePreference", { enumerable: true, get: function () { return __importDefault(price_preference_1).default; } });
@@ -0,0 +1,12 @@
1
+ export declare const uniquePreferenceRuleIndexName = "IDX_price_preference_attribute_value";
2
+ export default class PricePreference {
3
+ id: string;
4
+ attribute: string;
5
+ value: string | null;
6
+ is_tax_inclusive: boolean;
7
+ created_at: Date;
8
+ updated_at: Date;
9
+ deleted_at: Date | null;
10
+ onCreate(): void;
11
+ onInit(): void;
12
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.uniquePreferenceRuleIndexName = void 0;
13
+ const utils_1 = require("@medusajs/utils");
14
+ const core_1 = require("@mikro-orm/core");
15
+ exports.uniquePreferenceRuleIndexName = "IDX_price_preference_attribute_value";
16
+ const UniquePreferenceRuleIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
17
+ name: exports.uniquePreferenceRuleIndexName,
18
+ tableName: "price_preference",
19
+ columns: ["attribute", "value"],
20
+ unique: true,
21
+ where: "deleted_at IS NULL",
22
+ });
23
+ const DeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
24
+ tableName: "price_preference",
25
+ columns: "deleted_at",
26
+ where: "deleted_at IS NOT NULL",
27
+ });
28
+ let PricePreference = class PricePreference {
29
+ constructor() {
30
+ this.value = null;
31
+ this.deleted_at = null;
32
+ }
33
+ onCreate() {
34
+ this.id = (0, utils_1.generateEntityId)(this.id, "prpref");
35
+ }
36
+ onInit() {
37
+ this.id = (0, utils_1.generateEntityId)(this.id, "prpref");
38
+ }
39
+ };
40
+ __decorate([
41
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
42
+ __metadata("design:type", String)
43
+ ], PricePreference.prototype, "id", void 0);
44
+ __decorate([
45
+ (0, core_1.Property)({ columnType: "text" }),
46
+ __metadata("design:type", String)
47
+ ], PricePreference.prototype, "attribute", void 0);
48
+ __decorate([
49
+ (0, core_1.Property)({ columnType: "text", nullable: true }),
50
+ __metadata("design:type", Object)
51
+ ], PricePreference.prototype, "value", void 0);
52
+ __decorate([
53
+ (0, core_1.Property)({ default: false }),
54
+ __metadata("design:type", Boolean)
55
+ ], PricePreference.prototype, "is_tax_inclusive", void 0);
56
+ __decorate([
57
+ (0, core_1.Property)({
58
+ onCreate: () => new Date(),
59
+ columnType: "timestamptz",
60
+ defaultRaw: "now()",
61
+ }),
62
+ __metadata("design:type", Date)
63
+ ], PricePreference.prototype, "created_at", void 0);
64
+ __decorate([
65
+ (0, core_1.Property)({
66
+ onCreate: () => new Date(),
67
+ onUpdate: () => new Date(),
68
+ columnType: "timestamptz",
69
+ defaultRaw: "now()",
70
+ }),
71
+ __metadata("design:type", Date)
72
+ ], PricePreference.prototype, "updated_at", void 0);
73
+ __decorate([
74
+ DeletedAtIndex.MikroORMIndex(),
75
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
76
+ __metadata("design:type", Object)
77
+ ], PricePreference.prototype, "deleted_at", void 0);
78
+ __decorate([
79
+ (0, core_1.BeforeCreate)(),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", []),
82
+ __metadata("design:returntype", void 0)
83
+ ], PricePreference.prototype, "onCreate", null);
84
+ __decorate([
85
+ (0, core_1.OnInit)(),
86
+ __metadata("design:type", Function),
87
+ __metadata("design:paramtypes", []),
88
+ __metadata("design:returntype", void 0)
89
+ ], PricePreference.prototype, "onInit", null);
90
+ PricePreference = __decorate([
91
+ (0, core_1.Entity)(),
92
+ (0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions),
93
+ UniquePreferenceRuleIndexStatement.MikroORMIndex()
94
+ ], PricePreference);
95
+ exports.default = PricePreference;
@@ -54,10 +54,6 @@ class PricingRepository extends utils_1.MikroOrmBase {
54
54
  this.on("pl.id", "price.price_list_id").andOn("pl.status", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]));
55
55
  })
56
56
  .leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
57
- .orderBy([
58
- { column: "rules_count", order: "desc" },
59
- { column: "pl.rules_count", order: "desc" },
60
- ])
61
57
  .groupBy("price.id", "pl.id")
62
58
  .having(knex.raw("count(DISTINCT pr.attribute) = price.rules_count AND price.price_list_id IS NULL"))
63
59
  .orHaving(knex.raw("count(DISTINCT plr.attribute) = pl.rules_count AND price.price_list_id IS NOT NULL"));
@@ -120,7 +116,6 @@ class PricingRepository extends utils_1.MikroOrmBase {
120
116
  all_rules_count: knex.raw("COALESCE(price.rules_count, 0) + COALESCE(price.pl_rules_count, 0)"),
121
117
  })
122
118
  .join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
123
- .leftJoin("price_rule as pr", "pr.price_id", "price.id")
124
119
  .whereIn("ps.id", pricingFilters.id)
125
120
  .andWhere("price.currency_code", "=", currencyCode)
126
121
  .orderBy([
@@ -1,5 +1,5 @@
1
- import { AddPricesDTO, Context, CreatePriceRuleDTO, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes, UpsertPriceSetDTO } from "@medusajs/types";
2
- import { Price, PriceList, PriceListRule, PriceRule, PriceSet } from "../models";
1
+ import { AddPricesDTO, Context, CreatePriceRuleDTO, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PricePreferenceDTO, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes, UpsertPricePreferenceDTO, UpsertPriceSetDTO } from "@medusajs/types";
2
+ import { Price, PriceList, PriceListRule, PriceRule, PriceSet, PricePreference } from "../models";
3
3
  import { ServiceTypes } from "../types";
4
4
  import { CreatePriceListDTO } from "src/types/services";
5
5
  type InjectedDependencies = {
@@ -9,6 +9,7 @@ type InjectedDependencies = {
9
9
  priceRuleService: ModulesSdkTypes.IMedusaInternalService<any>;
10
10
  priceService: ModulesSdkTypes.IMedusaInternalService<any>;
11
11
  priceListService: ModulesSdkTypes.IMedusaInternalService<any>;
12
+ pricePreferenceService: ModulesSdkTypes.IMedusaInternalService<any>;
12
13
  priceListRuleService: ModulesSdkTypes.IMedusaInternalService<any>;
13
14
  };
14
15
  declare const PricingModuleService_base: import("@medusajs/utils/dist/modules-sdk/types/medusa-service").MedusaServiceReturnType<{
@@ -29,6 +30,9 @@ declare const PricingModuleService_base: import("@medusajs/utils/dist/modules-sd
29
30
  PriceListRule: {
30
31
  dto: PricingTypes.PriceListRuleDTO;
31
32
  };
33
+ PricePreference: {
34
+ dto: any;
35
+ };
32
36
  }>;
33
37
  export default class PricingModuleService extends PricingModuleService_base implements PricingTypes.IPricingModuleService {
34
38
  protected readonly moduleDeclaration: InternalModuleDeclaration;
@@ -39,7 +43,8 @@ export default class PricingModuleService extends PricingModuleService_base impl
39
43
  protected readonly priceService_: ModulesSdkTypes.IMedusaInternalService<Price>;
40
44
  protected readonly priceListService_: ModulesSdkTypes.IMedusaInternalService<PriceList>;
41
45
  protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceListRule>;
42
- constructor({ baseRepository, pricingRepository, priceSetService, priceRuleService, priceService, priceListService, priceListRuleService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
46
+ protected readonly pricePreferenceService_: ModulesSdkTypes.IMedusaInternalService<PricePreference>;
47
+ constructor({ baseRepository, pricingRepository, priceSetService, priceRuleService, priceService, pricePreferenceService, priceListService, priceListRuleService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
43
48
  __joinerConfig(): ModuleJoinerConfig;
44
49
  private setupCalculatedPriceConfig_;
45
50
  retrievePriceSet(id: string, config?: FindConfig<PriceSetDTO> | undefined, sharedContext?: Context | undefined): Promise<PriceSetDTO>;
@@ -64,6 +69,12 @@ export default class PricingModuleService extends PricingModuleService_base impl
64
69
  addPriceListPrices(data: PricingTypes.AddPriceListPricesDTO[], sharedContext?: Context): Promise<PricingTypes.PriceDTO[]>;
65
70
  setPriceListRules(data: PricingTypes.SetPriceListRulesDTO, sharedContext?: Context): Promise<PricingTypes.PriceListDTO>;
66
71
  removePriceListRules(data: PricingTypes.RemovePriceListRulesDTO, sharedContext?: Context): Promise<PricingTypes.PriceListDTO>;
72
+ createPricePreferences(data: PricingTypes.CreatePricePreferenceDTO, sharedContext?: Context): Promise<PricePreferenceDTO>;
73
+ createPricePreferences(data: PricingTypes.CreatePricePreferenceDTO[], sharedContext?: Context): Promise<PricePreferenceDTO[]>;
74
+ upsertPricePreferences(data: UpsertPricePreferenceDTO[], sharedContext?: Context): Promise<PricePreferenceDTO[]>;
75
+ upsertPricePreferences(data: UpsertPricePreferenceDTO, sharedContext?: Context): Promise<PricePreferenceDTO>;
76
+ updatePricePreferences(id: string, data: PricingTypes.UpdatePricePreferenceDTO, sharedContext?: Context): Promise<PricePreferenceDTO>;
77
+ updatePricePreferences(selector: PricingTypes.FilterablePricePreferenceProps, data: PricingTypes.UpdatePricePreferenceDTO, sharedContext?: Context): Promise<PricePreferenceDTO[]>;
67
78
  protected createPriceSets_(data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context): Promise<PriceSet[]>;
68
79
  protected addPrices_(input: AddPricesDTO[], sharedContext?: Context): Promise<Price[]>;
69
80
  protected createPriceLists_(data: PricingTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<PriceList[]>;
@@ -23,9 +23,10 @@ const generateMethodForModels = {
23
23
  PriceListRule: _models_1.PriceListRule,
24
24
  PriceRule: _models_1.PriceRule,
25
25
  Price: _models_1.Price,
26
+ PricePreference: _models_1.PricePreference,
26
27
  };
27
28
  class PricingModuleService extends utils_1.ModulesSdkUtils.MedusaService(generateMethodForModels) {
28
- constructor({ baseRepository, pricingRepository, priceSetService, priceRuleService, priceService, priceListService, priceListRuleService, }, moduleDeclaration) {
29
+ constructor({ baseRepository, pricingRepository, priceSetService, priceRuleService, priceService, pricePreferenceService, priceListService, priceListRuleService, }, moduleDeclaration) {
29
30
  // @ts-ignore
30
31
  super(...arguments);
31
32
  this.moduleDeclaration = moduleDeclaration;
@@ -34,6 +35,7 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.MedusaService(generat
34
35
  this.priceSetService_ = priceSetService;
35
36
  this.priceRuleService_ = priceRuleService;
36
37
  this.priceService_ = priceService;
38
+ this.pricePreferenceService_ = pricePreferenceService;
37
39
  this.priceListService_ = priceListService;
38
40
  this.priceListRuleService_ = priceListRuleService;
39
41
  }
@@ -98,17 +100,14 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.MedusaService(generat
98
100
  async calculatePrices(pricingFilters, pricingContext = { context: {} }, sharedContext = {}) {
99
101
  const results = await this.pricingRepository_.calculatePrices(pricingFilters, pricingContext, sharedContext);
100
102
  const pricesSetPricesMap = (0, utils_1.groupBy)(results, "price_set_id");
101
- const calculatedPrices = pricingFilters.id
102
- .map((priceSetId) => {
103
- // This is where we select prices, for now we just do a first match based on the database results
104
- // which is prioritized by rules_count first for exact match and then deafult_priority of the rule_type
105
- // TODO: inject custom price selection here
106
- const prices = pricesSetPricesMap.get(priceSetId) || [];
107
- if (!prices.length) {
108
- return null;
109
- }
103
+ const priceIds = [];
104
+ pricesSetPricesMap.forEach((prices, key) => {
110
105
  const priceListPrice = prices.find((p) => p.price_list_id);
111
106
  const defaultPrice = prices?.find((p) => !p.price_list_id);
107
+ if (!prices.length || (!priceListPrice && !defaultPrice)) {
108
+ pricesSetPricesMap.delete(key);
109
+ return;
110
+ }
112
111
  let calculatedPrice = defaultPrice;
113
112
  let originalPrice = defaultPrice;
114
113
  if (priceListPrice) {
@@ -117,11 +116,40 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.MedusaService(generat
117
116
  originalPrice = priceListPrice;
118
117
  }
119
118
  }
119
+ pricesSetPricesMap.set(key, { calculatedPrice, originalPrice });
120
+ priceIds.push(...(0, utils_1.deduplicate)([calculatedPrice?.id, originalPrice?.id].filter(Boolean)));
121
+ });
122
+ // We use the price rules to get the right preferences for the price
123
+ const priceRulesForPrices = await this.priceRuleService_.list({ price_id: priceIds }, { take: null });
124
+ const priceRulesPriceMap = (0, utils_1.groupBy)(priceRulesForPrices, "price_id");
125
+ // Note: For now the preferences are intentionally kept very simple and explicit - they use either the region or currency,
126
+ // so we hard-code those as the possible filters here. This can be made more flexible if needed later on.
127
+ const pricingPreferences = await this.pricePreferenceService_.list({
128
+ $or: Object.entries(pricingContext)
129
+ .filter(([key, val]) => {
130
+ return key === "region_id" || key === "currency_code";
131
+ })
132
+ .map(([key, val]) => ({
133
+ attribute: key,
134
+ value: val,
135
+ })),
136
+ }, {}, sharedContext);
137
+ const calculatedPrices = pricingFilters.id
138
+ .map((priceSetId) => {
139
+ const prices = pricesSetPricesMap.get(priceSetId);
140
+ if (!prices) {
141
+ return null;
142
+ }
143
+ const { calculatedPrice, originalPrice, } = prices;
120
144
  return {
121
145
  id: priceSetId,
122
146
  is_calculated_price_price_list: !!calculatedPrice?.price_list_id,
147
+ is_calculated_price_tax_inclusive: isTaxInclusive(priceRulesPriceMap.get(calculatedPrice.id), pricingPreferences),
123
148
  calculated_amount: parseInt(calculatedPrice?.amount || "") || null,
124
149
  is_original_price_price_list: !!originalPrice?.price_list_id,
150
+ is_original_price_tax_inclusive: originalPrice?.id
151
+ ? isTaxInclusive(priceRulesPriceMap.get(originalPrice.id), pricingPreferences)
152
+ : false,
125
153
  original_amount: parseInt(originalPrice?.amount || "") || null,
126
154
  currency_code: calculatedPrice?.currency_code || null,
127
155
  calculated_price: {
@@ -291,6 +319,28 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.MedusaService(generat
291
319
  const [priceList] = await this.removePriceListRules_([data], sharedContext);
292
320
  return await this.baseRepository_.serialize(priceList);
293
321
  }
322
+ async createPricePreferences(data, sharedContext = {}) {
323
+ const preferences = await this.pricePreferenceService_.create(data, sharedContext);
324
+ return await this.baseRepository_.serialize(preferences);
325
+ }
326
+ async upsertPricePreferences(data, sharedContext = {}) {
327
+ const input = Array.isArray(data) ? data : [data];
328
+ const forUpdate = input.filter((pricePreference) => !!pricePreference.id);
329
+ const forCreate = input.filter((pricePreference) => !pricePreference.id);
330
+ const operations = [];
331
+ if (forCreate.length) {
332
+ operations.push(this.pricePreferenceService_.create(forCreate, sharedContext));
333
+ }
334
+ if (forUpdate.length) {
335
+ operations.push(this.pricePreferenceService_.update(forUpdate, sharedContext));
336
+ }
337
+ const result = (await (0, utils_1.promiseAll)(operations)).flat();
338
+ return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
339
+ }
340
+ async updatePricePreferences(idOrSelector, data, sharedContext = {}) {
341
+ const preferences = await this.pricePreferenceService_.update(data, sharedContext);
342
+ return await this.baseRepository_.serialize(preferences);
343
+ }
294
344
  async createPriceSets_(data, sharedContext = {}) {
295
345
  const input = Array.isArray(data) ? data : [data];
296
346
  const toCreate = input.map((inputData) => {
@@ -790,6 +840,28 @@ __decorate([
790
840
  __metadata("design:paramtypes", [Object, Object]),
791
841
  __metadata("design:returntype", Promise)
792
842
  ], PricingModuleService.prototype, "removePriceListRules", null);
843
+ __decorate([
844
+ (0, utils_1.InjectManager)("baseRepository_"),
845
+ (0, utils_1.EmitEvents)(),
846
+ __param(1, (0, utils_1.MedusaContext)()),
847
+ __metadata("design:type", Function),
848
+ __metadata("design:paramtypes", [Object, Object]),
849
+ __metadata("design:returntype", Promise)
850
+ ], PricingModuleService.prototype, "createPricePreferences", null);
851
+ __decorate([
852
+ (0, utils_1.InjectManager)("baseRepository_"),
853
+ __param(1, (0, utils_1.MedusaContext)()),
854
+ __metadata("design:type", Function),
855
+ __metadata("design:paramtypes", [Object, Object]),
856
+ __metadata("design:returntype", Promise)
857
+ ], PricingModuleService.prototype, "upsertPricePreferences", null);
858
+ __decorate([
859
+ (0, utils_1.InjectManager)("baseRepository_"),
860
+ __param(2, (0, utils_1.MedusaContext)()),
861
+ __metadata("design:type", Function),
862
+ __metadata("design:paramtypes", [Object, Object, Object]),
863
+ __metadata("design:returntype", Promise)
864
+ ], PricingModuleService.prototype, "updatePricePreferences", null);
793
865
  __decorate([
794
866
  (0, utils_1.InjectTransactionManager)("baseRepository_"),
795
867
  __param(1, (0, utils_1.MedusaContext)()),
@@ -848,6 +920,20 @@ __decorate([
848
920
  __metadata("design:paramtypes", [Array, Object]),
849
921
  __metadata("design:returntype", Promise)
850
922
  ], PricingModuleService.prototype, "removePriceListRules_", null);
923
+ const isTaxInclusive = (priceRules, preferences) => {
924
+ const regionPreference = preferences.find((p) => p.attribute === "region_id");
925
+ const currencyPreference = preferences.find((p) => p.attribute === "currency_code");
926
+ const regionRule = priceRules?.find((rule) => rule.attribute === "region_id");
927
+ if (regionRule &&
928
+ regionPreference &&
929
+ regionRule.value === regionPreference.value) {
930
+ return regionPreference.is_tax_inclusive;
931
+ }
932
+ if (currencyPreference) {
933
+ return currencyPreference.is_tax_inclusive;
934
+ }
935
+ return false;
936
+ };
851
937
  const hashPrice = (price) => {
852
938
  const data = Object.entries({
853
939
  currency_code: price.currency_code,
@@ -1,3 +1,29 @@
1
- export * from "./price-list";
2
- export * from "./price-set";
3
- export * from "./price";
1
+ import { PriceListStatus, PricingTypes } from "@medusajs/types";
2
+ export interface CreatePriceListDTO extends PricingTypes.CreatePriceListDTO {
3
+ rules_count?: number;
4
+ price_list_rules?: {
5
+ attribute: string;
6
+ value: string;
7
+ }[];
8
+ prices?: PricingTypes.CreatePriceListPriceDTO[];
9
+ }
10
+ export interface UpdatePriceListDTO {
11
+ id: string;
12
+ title?: string;
13
+ description?: string | null;
14
+ starts_at?: string | null;
15
+ ends_at?: string | null;
16
+ status?: PriceListStatus;
17
+ number_rules?: number;
18
+ }
19
+ export interface UpdatePriceSetInput extends PricingTypes.UpdatePriceSetDTO {
20
+ id: string;
21
+ }
22
+ export interface UpsertPriceDTO extends Omit<PricingTypes.CreatePriceDTO, "rules"> {
23
+ id?: string;
24
+ price_list_id?: string;
25
+ price_rules: PricingTypes.CreatePriceRuleDTO[];
26
+ }
27
+ export interface UpdatePricePreferenceInput extends PricingTypes.UpdatePricePreferenceDTO {
28
+ id: string;
29
+ }
@@ -1,19 +1,2 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./price-list"), exports);
18
- __exportStar(require("./price-set"), exports);
19
- __exportStar(require("./price"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/pricing",
3
- "version": "0.1.13-preview-20240704133323",
3
+ "version": "0.1.13-preview-20240704145232",
4
4
  "description": "Medusa Pricing module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "@mikro-orm/cli": "5.9.7",
38
38
  "cross-env": "^5.2.1",
39
39
  "jest": "^29.7.0",
40
- "medusa-test-utils": "1.1.45-preview-20240704133323",
40
+ "medusa-test-utils": "1.1.45-preview-20240704145232",
41
41
  "rimraf": "^3.0.2",
42
42
  "ts-jest": "^29.1.1",
43
43
  "ts-node": "^10.9.1",
@@ -45,9 +45,9 @@
45
45
  "typescript": "^5.1.6"
46
46
  },
47
47
  "dependencies": {
48
- "@medusajs/modules-sdk": "1.13.0-preview-20240704133323",
49
- "@medusajs/types": "1.12.0-preview-20240704133323",
50
- "@medusajs/utils": "1.12.0-preview-20240704133323",
48
+ "@medusajs/modules-sdk": "1.13.0-preview-20240704145232",
49
+ "@medusajs/types": "1.12.0-preview-20240704145232",
50
+ "@medusajs/utils": "1.12.0-preview-20240704145232",
51
51
  "@mikro-orm/core": "5.9.7",
52
52
  "@mikro-orm/migrations": "5.9.7",
53
53
  "@mikro-orm/postgresql": "5.9.7",
@@ -1,18 +0,0 @@
1
- import { PriceListStatus, PricingTypes } from "@medusajs/types";
2
- export interface CreatePriceListDTO extends PricingTypes.CreatePriceListDTO {
3
- rules_count?: number;
4
- price_list_rules?: {
5
- attribute: string;
6
- value: string;
7
- }[];
8
- prices?: PricingTypes.CreatePriceListPriceDTO[];
9
- }
10
- export interface UpdatePriceListDTO {
11
- id: string;
12
- title?: string;
13
- description?: string | null;
14
- starts_at?: string | null;
15
- ends_at?: string | null;
16
- status?: PriceListStatus;
17
- number_rules?: number;
18
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- import { UpdatePriceSetDTO } from "@medusajs/types";
2
- export interface UpdatePriceSetInput extends UpdatePriceSetDTO {
3
- id: string;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- import { PricingTypes } from "@medusajs/types";
2
- export interface UpsertPriceDTO extends Omit<PricingTypes.CreatePriceDTO, "rules"> {
3
- id?: string;
4
- price_list_id?: string;
5
- price_rules: PricingTypes.CreatePriceRuleDTO[];
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });