@medusajs/pricing 2.11.0-snapshot-20250829134337 → 2.11.0-snapshot-20251016104801
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/dist/migrations/Migration20230929122253.d.ts +1 -1
- package/dist/migrations/Migration20230929122253.d.ts.map +1 -1
- package/dist/migrations/Migration20230929122253.js +1 -1
- package/dist/migrations/Migration20230929122253.js.map +1 -1
- package/dist/migrations/Migration20240322094407.d.ts +1 -1
- package/dist/migrations/Migration20240322094407.d.ts.map +1 -1
- package/dist/migrations/Migration20240322094407.js +1 -1
- package/dist/migrations/Migration20240322094407.js.map +1 -1
- package/dist/migrations/Migration20240322113359.d.ts +1 -1
- package/dist/migrations/Migration20240322113359.d.ts.map +1 -1
- package/dist/migrations/Migration20240322113359.js +1 -1
- package/dist/migrations/Migration20240322113359.js.map +1 -1
- package/dist/migrations/Migration20240322120125.d.ts +1 -1
- package/dist/migrations/Migration20240322120125.d.ts.map +1 -1
- package/dist/migrations/Migration20240322120125.js +1 -1
- package/dist/migrations/Migration20240322120125.js.map +1 -1
- package/dist/migrations/Migration20240626133555.d.ts +1 -1
- package/dist/migrations/Migration20240626133555.d.ts.map +1 -1
- package/dist/migrations/Migration20240626133555.js +1 -1
- package/dist/migrations/Migration20240626133555.js.map +1 -1
- package/dist/migrations/Migration20240704094505.d.ts +1 -1
- package/dist/migrations/Migration20240704094505.d.ts.map +1 -1
- package/dist/migrations/Migration20240704094505.js +1 -1
- package/dist/migrations/Migration20240704094505.js.map +1 -1
- package/dist/migrations/Migration20241127114534.d.ts +1 -1
- package/dist/migrations/Migration20241127114534.d.ts.map +1 -1
- package/dist/migrations/Migration20241127114534.js +1 -1
- package/dist/migrations/Migration20241127114534.js.map +1 -1
- package/dist/migrations/Migration20241127223829.d.ts +1 -1
- package/dist/migrations/Migration20241127223829.d.ts.map +1 -1
- package/dist/migrations/Migration20241127223829.js +1 -1
- package/dist/migrations/Migration20241127223829.js.map +1 -1
- package/dist/migrations/Migration20241128055359.d.ts +1 -1
- package/dist/migrations/Migration20241128055359.d.ts.map +1 -1
- package/dist/migrations/Migration20241128055359.js +1 -1
- package/dist/migrations/Migration20241128055359.js.map +1 -1
- package/dist/migrations/Migration20241212190401.d.ts +1 -1
- package/dist/migrations/Migration20241212190401.d.ts.map +1 -1
- package/dist/migrations/Migration20241212190401.js +1 -1
- package/dist/migrations/Migration20241212190401.js.map +1 -1
- package/dist/migrations/Migration20250408145122.d.ts +1 -1
- package/dist/migrations/Migration20250408145122.d.ts.map +1 -1
- package/dist/migrations/Migration20250408145122.js +1 -1
- package/dist/migrations/Migration20250408145122.js.map +1 -1
- package/dist/migrations/Migration20250409122219.d.ts +1 -1
- package/dist/migrations/Migration20250409122219.d.ts.map +1 -1
- package/dist/migrations/Migration20250409122219.js +1 -1
- package/dist/migrations/Migration20250409122219.js.map +1 -1
- package/dist/migrations/Migration20251009110625.d.ts +6 -0
- package/dist/migrations/Migration20251009110625.d.ts.map +1 -0
- package/dist/migrations/Migration20251009110625.js +18 -0
- package/dist/migrations/Migration20251009110625.js.map +1 -0
- package/dist/models/price-list-rule.d.ts.map +1 -1
- package/dist/models/price-list-rule.js +5 -0
- package/dist/models/price-list-rule.js.map +1 -1
- package/dist/models/price-list.d.ts.map +1 -1
- package/dist/models/price-list.js +7 -1
- package/dist/models/price-list.js.map +1 -1
- package/dist/models/price-rule.d.ts.map +1 -1
- package/dist/models/price-rule.js +4 -0
- package/dist/models/price-rule.js.map +1 -1
- package/dist/repositories/pricing.d.ts.map +1 -1
- package/dist/repositories/pricing.js +57 -61
- package/dist/repositories/pricing.js.map +1 -1
- package/dist/services/pricing-module.d.ts +9 -2
- package/dist/services/pricing-module.d.ts.map +1 -1
- package/dist/services/pricing-module.js +141 -202
- package/dist/services/pricing-module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +9 -17
- package/dist/utils/events.d.ts +0 -123
- package/dist/utils/events.d.ts.map +0 -1
- package/dist/utils/events.js +0 -97
- package/dist/utils/events.js.map +0 -1
@@ -31,6 +31,7 @@ class PricingModuleService extends BaseClass {
|
|
31
31
|
// @ts-ignore
|
32
32
|
super(...arguments);
|
33
33
|
this.moduleDeclaration = moduleDeclaration;
|
34
|
+
this.container_ = arguments[0];
|
34
35
|
this.baseRepository_ = baseRepository;
|
35
36
|
this.pricingRepository_ = pricingRepository;
|
36
37
|
this.priceSetService_ = priceSetService;
|
@@ -115,7 +116,7 @@ class PricingModuleService extends BaseClass {
|
|
115
116
|
const calculatedPrice = calculatedPricesMap.get(priceSet.id);
|
116
117
|
priceSet.calculated_price = calculatedPrice ?? null;
|
117
118
|
}
|
118
|
-
return priceSets;
|
119
|
+
return await this.baseRepository_.serialize(priceSets);
|
119
120
|
}
|
120
121
|
// @ts-expect-error
|
121
122
|
async listAndCountPriceSets(filters = {}, config = {}, sharedContext = {}) {
|
@@ -123,7 +124,8 @@ class PricingModuleService extends BaseClass {
|
|
123
124
|
const pricingContext = this.setupCalculatedPriceConfig_(filters, normalizedConfig);
|
124
125
|
const [priceSets, count] = await super.listAndCountPriceSets(filters, normalizedConfig, sharedContext);
|
125
126
|
if (!pricingContext || !priceSets.length) {
|
126
|
-
|
127
|
+
const serializedPriceSets = await this.baseRepository_.serialize(priceSets);
|
128
|
+
return [serializedPriceSets, count];
|
127
129
|
}
|
128
130
|
const calculatedPrices = await this.calculatePrices({ id: priceSets.map((p) => p.id) }, { context: pricingContext }, sharedContext);
|
129
131
|
const calculatedPricesMap = new Map();
|
@@ -134,7 +136,24 @@ class PricingModuleService extends BaseClass {
|
|
134
136
|
const calculatedPrice = calculatedPricesMap.get(priceSet.id);
|
135
137
|
priceSet.calculated_price = calculatedPrice ?? null;
|
136
138
|
}
|
137
|
-
|
139
|
+
const serializedPriceSets = await this.baseRepository_.serialize(priceSets);
|
140
|
+
return [serializedPriceSets, count];
|
141
|
+
}
|
142
|
+
// @ts-expect-error
|
143
|
+
async listPriceRules(filters, config = {}, sharedContext) {
|
144
|
+
const priceRules = await this.listPriceRules_(filters, config, sharedContext);
|
145
|
+
return await this.baseRepository_.serialize(priceRules);
|
146
|
+
}
|
147
|
+
async listPriceRules_(filters, config = {}, sharedContext) {
|
148
|
+
return await this.priceRuleService_.list(filters, config, sharedContext);
|
149
|
+
}
|
150
|
+
// @ts-expect-error
|
151
|
+
async listPricePreferences(filters, config = {}, sharedContext) {
|
152
|
+
const pricePreferences = await this.listPricePreferences_(filters, { ...config, select: [...(config.select || []), "id"] }, sharedContext);
|
153
|
+
return await this.baseRepository_.serialize(pricePreferences);
|
154
|
+
}
|
155
|
+
async listPricePreferences_(filters, config = {}, sharedContext) {
|
156
|
+
return await this.pricePreferenceService_.list(filters, config, sharedContext);
|
138
157
|
}
|
139
158
|
async calculatePrices(pricingFilters, pricingContext = { context: {} }, sharedContext = {}) {
|
140
159
|
const results = await this.pricingRepository_.calculatePrices(pricingFilters, pricingContext, sharedContext);
|
@@ -177,28 +196,33 @@ class PricingModuleService extends BaseClass {
|
|
177
196
|
priceIds.push(...(0, utils_1.deduplicate)([calculatedPrice?.id, originalPrice?.id].filter(Boolean)));
|
178
197
|
});
|
179
198
|
// We use the price rules to get the right preferences for the price
|
180
|
-
const priceRulesForPrices = await this.
|
199
|
+
const priceRulesForPrices = await this.listPriceRules({ price_id: priceIds }, {}, sharedContext);
|
181
200
|
const priceRulesPriceMap = (0, utils_1.groupBy)(priceRulesForPrices, "price_id");
|
182
201
|
// Note: For now the preferences are intentionally kept very simple and explicit - they use either the region or currency,
|
183
202
|
// so we hard-code those as the possible filters here. This can be made more flexible if needed later on.
|
184
|
-
const
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
203
|
+
const preferenceContext = Object.entries(pricingContext.context ?? {}).filter(([key, val]) => {
|
204
|
+
return key === "region_id" || key === "currency_code";
|
205
|
+
});
|
206
|
+
let pricingPreferences = [];
|
207
|
+
if (preferenceContext.length) {
|
208
|
+
const preferenceFilters = preferenceContext.length
|
209
|
+
? {
|
210
|
+
$or: preferenceContext.map(([key, val]) => ({
|
211
|
+
attribute: key,
|
212
|
+
value: val,
|
213
|
+
})),
|
214
|
+
}
|
215
|
+
: {};
|
216
|
+
pricingPreferences = await this.listPricePreferences_(preferenceFilters, {}, sharedContext);
|
217
|
+
}
|
218
|
+
const calculatedPrices = [];
|
219
|
+
for (const priceSetId of pricingFilters.id) {
|
196
220
|
const prices = pricesSetPricesMap.get(priceSetId);
|
197
221
|
if (!prices) {
|
198
|
-
|
222
|
+
continue;
|
199
223
|
}
|
200
224
|
const { calculatedPrice, originalPrice, } = prices;
|
201
|
-
|
225
|
+
const calculatedPrice_ = {
|
202
226
|
id: priceSetId,
|
203
227
|
is_calculated_price_price_list: !!calculatedPrice?.price_list_id,
|
204
228
|
is_calculated_price_tax_inclusive: isTaxInclusive(priceRulesPriceMap.get(calculatedPrice.id), pricingPreferences, calculatedPrice.currency_code, pricingContext.context?.region_id),
|
@@ -230,9 +254,9 @@ class PricingModuleService extends BaseClass {
|
|
230
254
|
max_quantity: parseInt(originalPrice?.max_quantity || "") || null,
|
231
255
|
},
|
232
256
|
};
|
233
|
-
|
234
|
-
|
235
|
-
return
|
257
|
+
calculatedPrices.push(calculatedPrice_);
|
258
|
+
}
|
259
|
+
return calculatedPrices;
|
236
260
|
}
|
237
261
|
// @ts-expect-error
|
238
262
|
async createPriceSets(data, sharedContext = {}) {
|
@@ -254,6 +278,15 @@ class PricingModuleService extends BaseClass {
|
|
254
278
|
}
|
255
279
|
}
|
256
280
|
async upsertPriceSets(data, sharedContext = {}) {
|
281
|
+
const result = await this.upsertPriceSets_(data, sharedContext);
|
282
|
+
try {
|
283
|
+
return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
|
284
|
+
}
|
285
|
+
finally {
|
286
|
+
this.pricingRepository_.clearAvailableAttributes?.();
|
287
|
+
}
|
288
|
+
}
|
289
|
+
async upsertPriceSets_(data, sharedContext = {}) {
|
257
290
|
const input = Array.isArray(data) ? data : [data];
|
258
291
|
const forUpdate = input.filter((priceSet) => !!priceSet.id);
|
259
292
|
const forCreate = input.filter((priceSet) => !priceSet.id);
|
@@ -265,12 +298,7 @@ class PricingModuleService extends BaseClass {
|
|
265
298
|
operations.push(this.updatePriceSets_(forUpdate, sharedContext));
|
266
299
|
}
|
267
300
|
const result = (await (0, utils_1.promiseAll)(operations)).flat();
|
268
|
-
|
269
|
-
return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
|
270
|
-
}
|
271
|
-
finally {
|
272
|
-
this.pricingRepository_.clearAvailableAttributes?.();
|
273
|
-
}
|
301
|
+
return result;
|
274
302
|
}
|
275
303
|
// @ts-expect-error
|
276
304
|
async updatePriceSets(idOrSelector, data, sharedContext = {}) {
|
@@ -288,9 +316,9 @@ class PricingModuleService extends BaseClass {
|
|
288
316
|
}));
|
289
317
|
}
|
290
318
|
const updateResult = await this.updatePriceSets_(normalizedInput, sharedContext);
|
291
|
-
const
|
319
|
+
const serializedUpdateResult = await this.baseRepository_.serialize((0, utils_1.isString)(idOrSelector) ? updateResult[0] : updateResult);
|
292
320
|
try {
|
293
|
-
return
|
321
|
+
return serializedUpdateResult;
|
294
322
|
}
|
295
323
|
finally {
|
296
324
|
this.pricingRepository_.clearAvailableAttributes?.();
|
@@ -345,24 +373,12 @@ class PricingModuleService extends BaseClass {
|
|
345
373
|
...rule,
|
346
374
|
price_id: priceToUpdate.id,
|
347
375
|
})), sharedContext);
|
348
|
-
_utils_1.eventBuilders.createdPriceRule({
|
349
|
-
data: createdPriceRules.map((r) => ({ id: r.id })),
|
350
|
-
sharedContext,
|
351
|
-
});
|
352
376
|
}
|
353
377
|
if (priceRulesToUpdate.length > 0) {
|
354
378
|
updatedPriceRules = await this.priceRuleService_.update(priceRulesToUpdate, sharedContext);
|
355
|
-
_utils_1.eventBuilders.updatedPriceRule({
|
356
|
-
data: updatedPriceRules.map((r) => ({ id: r.id })),
|
357
|
-
sharedContext,
|
358
|
-
});
|
359
379
|
}
|
360
380
|
if (priceRulesToDelete.length > 0) {
|
361
381
|
await this.priceRuleService_.delete(priceRulesToDelete, sharedContext);
|
362
|
-
_utils_1.eventBuilders.deletedPriceRule({
|
363
|
-
data: priceRulesToDelete.map((id) => ({ id })),
|
364
|
-
sharedContext,
|
365
|
-
});
|
366
382
|
}
|
367
383
|
const upsertedPriceRules = [
|
368
384
|
...createdPriceRules,
|
@@ -379,10 +395,6 @@ class PricingModuleService extends BaseClass {
|
|
379
395
|
const priceRuleToDelete = existingPrice?.price_rules?.map((r) => r.id);
|
380
396
|
if (priceRuleToDelete?.length) {
|
381
397
|
await this.priceRuleService_.delete(priceRuleToDelete, sharedContext);
|
382
|
-
_utils_1.eventBuilders.deletedPriceRule({
|
383
|
-
data: priceRuleToDelete.map((id) => ({ id })),
|
384
|
-
sharedContext,
|
385
|
-
});
|
386
398
|
}
|
387
399
|
;
|
388
400
|
priceToUpdate.rules_count = 0;
|
@@ -399,24 +411,6 @@ class PricingModuleService extends BaseClass {
|
|
399
411
|
if (pricesToDelete.length > 0) {
|
400
412
|
await this.priceService_.delete(pricesToDelete, sharedContext);
|
401
413
|
}
|
402
|
-
if (createdPrices.length > 0) {
|
403
|
-
_utils_1.eventBuilders.createdPrice({
|
404
|
-
data: createdPrices.map((p) => ({ id: p.id })),
|
405
|
-
sharedContext,
|
406
|
-
});
|
407
|
-
}
|
408
|
-
if (updatedPrices.length > 0) {
|
409
|
-
_utils_1.eventBuilders.updatedPrice({
|
410
|
-
data: updatedPrices.map((p) => ({ id: p.id })),
|
411
|
-
sharedContext,
|
412
|
-
});
|
413
|
-
}
|
414
|
-
if (pricesToDelete.length > 0) {
|
415
|
-
_utils_1.eventBuilders.deletedPrice({
|
416
|
-
data: pricesToDelete.map((id) => ({ id })),
|
417
|
-
sharedContext,
|
418
|
-
});
|
419
|
-
}
|
420
414
|
const priceSets = await this.priceSetService_.list({ id: normalizedData.map(({ id }) => id) }, {
|
421
415
|
relations: ["prices", "prices.price_rules"],
|
422
416
|
}, sharedContext);
|
@@ -432,10 +426,6 @@ class PricingModuleService extends BaseClass {
|
|
432
426
|
priceSets.forEach((ps) => {
|
433
427
|
ps.prices = upsertedPricesMap.get(ps.id) || [];
|
434
428
|
});
|
435
|
-
_utils_1.eventBuilders.updatedPriceSet({
|
436
|
-
data: priceSets.map((ps) => ({ id: ps.id })),
|
437
|
-
sharedContext,
|
438
|
-
});
|
439
429
|
return priceSets;
|
440
430
|
}
|
441
431
|
async normalizeUpdateData(data) {
|
@@ -468,7 +458,8 @@ class PricingModuleService extends BaseClass {
|
|
468
458
|
return {
|
469
459
|
attribute,
|
470
460
|
operator: customRule.operator,
|
471
|
-
|
461
|
+
// TODO: we throw above if value is not a number, but the model expect the value to be a string
|
462
|
+
value: customRule.value.toString(),
|
472
463
|
};
|
473
464
|
});
|
474
465
|
}
|
@@ -505,8 +496,9 @@ class PricingModuleService extends BaseClass {
|
|
505
496
|
const orderedPriceSets = input.map((inputItem) => {
|
506
497
|
return dbPrices.find((p) => p.id === inputItem.priceSetId);
|
507
498
|
});
|
499
|
+
const serializedOrderedPriceSets = await this.baseRepository_.serialize(Array.isArray(data) ? orderedPriceSets : orderedPriceSets[0]);
|
508
500
|
try {
|
509
|
-
return
|
501
|
+
return serializedOrderedPriceSets;
|
510
502
|
}
|
511
503
|
finally {
|
512
504
|
this.pricingRepository_.clearAvailableAttributes?.();
|
@@ -578,6 +570,10 @@ class PricingModuleService extends BaseClass {
|
|
578
570
|
return Array.isArray(data) ? serialized : serialized[0];
|
579
571
|
}
|
580
572
|
async upsertPricePreferences(data, sharedContext = {}) {
|
573
|
+
const result = await this.upsertPricePreferences_(data, sharedContext);
|
574
|
+
return await this.baseRepository_.serialize(Array.isArray(data) ? result : result[0]);
|
575
|
+
}
|
576
|
+
async upsertPricePreferences_(data, sharedContext = {}) {
|
581
577
|
const input = Array.isArray(data) ? data : [data];
|
582
578
|
const forUpdate = input.filter((pricePreference) => !!pricePreference.id);
|
583
579
|
const forCreate = input.filter((pricePreference) => !pricePreference.id);
|
@@ -589,7 +585,7 @@ class PricingModuleService extends BaseClass {
|
|
589
585
|
operations.push(this.updatePricePreferences_(forUpdate, sharedContext));
|
590
586
|
}
|
591
587
|
const result = (await (0, utils_1.promiseAll)(operations)).flat();
|
592
|
-
return
|
588
|
+
return result;
|
593
589
|
}
|
594
590
|
// @ts-expect-error
|
595
591
|
async updatePricePreferences(idOrSelector, data, sharedContext = {}) {
|
@@ -632,38 +628,6 @@ class PricingModuleService extends BaseClass {
|
|
632
628
|
});
|
633
629
|
// Bulk create price sets
|
634
630
|
const priceSets = await this.priceSetService_.create(toCreate, sharedContext);
|
635
|
-
const eventsData = priceSets.reduce((eventsData, priceSet) => {
|
636
|
-
eventsData.priceSets.push({
|
637
|
-
id: priceSet.id,
|
638
|
-
});
|
639
|
-
priceSet.prices.map((price) => {
|
640
|
-
eventsData.prices.push({
|
641
|
-
id: price.id,
|
642
|
-
});
|
643
|
-
price.price_rules.map((priceRule) => {
|
644
|
-
eventsData.priceRules.push({
|
645
|
-
id: priceRule.id,
|
646
|
-
});
|
647
|
-
});
|
648
|
-
});
|
649
|
-
return eventsData;
|
650
|
-
}, {
|
651
|
-
priceSets: [],
|
652
|
-
priceRules: [],
|
653
|
-
prices: [],
|
654
|
-
});
|
655
|
-
_utils_1.eventBuilders.createdPriceSet({
|
656
|
-
data: eventsData.priceSets,
|
657
|
-
sharedContext,
|
658
|
-
});
|
659
|
-
_utils_1.eventBuilders.createdPrice({
|
660
|
-
data: eventsData.prices,
|
661
|
-
sharedContext,
|
662
|
-
});
|
663
|
-
_utils_1.eventBuilders.createdPriceRule({
|
664
|
-
data: eventsData.priceRules,
|
665
|
-
sharedContext,
|
666
|
-
});
|
667
631
|
return priceSets;
|
668
632
|
}
|
669
633
|
async addPrices_(input, sharedContext = {}) {
|
@@ -685,12 +649,7 @@ class PricingModuleService extends BaseClass {
|
|
685
649
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Price set with id: ${price.price_set_id} not found`);
|
686
650
|
}
|
687
651
|
});
|
688
|
-
const { entities
|
689
|
-
composeAllEvents({
|
690
|
-
eventBuilders: _utils_1.eventBuilders,
|
691
|
-
performedActions,
|
692
|
-
sharedContext,
|
693
|
-
});
|
652
|
+
const { entities } = await this.priceService_.upsertWithReplace(pricesToUpsert, { relations: ["price_rules"] }, sharedContext);
|
694
653
|
return entities;
|
695
654
|
}
|
696
655
|
async createPriceLists_(data, sharedContext = {}) {
|
@@ -723,54 +682,6 @@ class PricingModuleService extends BaseClass {
|
|
723
682
|
return entry;
|
724
683
|
});
|
725
684
|
const priceLists = await this.priceListService_.create(priceListsToCreate, sharedContext);
|
726
|
-
/**
|
727
|
-
* Preparing data for emitting events
|
728
|
-
*/
|
729
|
-
const eventsData = priceLists.reduce((eventsData, priceList) => {
|
730
|
-
eventsData.priceList.push({
|
731
|
-
id: priceList.id,
|
732
|
-
});
|
733
|
-
priceList.price_list_rules.map((listRule) => {
|
734
|
-
eventsData.priceListRules.push({
|
735
|
-
id: listRule.id,
|
736
|
-
});
|
737
|
-
});
|
738
|
-
priceList.prices.map((price) => {
|
739
|
-
eventsData.prices.push({
|
740
|
-
id: price.id,
|
741
|
-
});
|
742
|
-
price.price_rules.map((priceRule) => {
|
743
|
-
eventsData.priceRules.push({
|
744
|
-
id: priceRule.id,
|
745
|
-
});
|
746
|
-
});
|
747
|
-
});
|
748
|
-
return eventsData;
|
749
|
-
}, {
|
750
|
-
priceList: [],
|
751
|
-
priceListRules: [],
|
752
|
-
priceRules: [],
|
753
|
-
prices: [],
|
754
|
-
});
|
755
|
-
/**
|
756
|
-
* Emitting events for all created entities
|
757
|
-
*/
|
758
|
-
_utils_1.eventBuilders.createdPriceList({
|
759
|
-
data: eventsData.priceList,
|
760
|
-
sharedContext,
|
761
|
-
});
|
762
|
-
_utils_1.eventBuilders.createdPriceListRule({
|
763
|
-
data: eventsData.priceListRules,
|
764
|
-
sharedContext,
|
765
|
-
});
|
766
|
-
_utils_1.eventBuilders.createdPrice({
|
767
|
-
data: eventsData.prices,
|
768
|
-
sharedContext,
|
769
|
-
});
|
770
|
-
_utils_1.eventBuilders.createdPriceRule({
|
771
|
-
data: eventsData.priceRules,
|
772
|
-
sharedContext,
|
773
|
-
});
|
774
685
|
return priceLists;
|
775
686
|
}
|
776
687
|
async updatePriceLists_(data, sharedContext = {}) {
|
@@ -804,14 +715,9 @@ class PricingModuleService extends BaseClass {
|
|
804
715
|
}
|
805
716
|
return entry;
|
806
717
|
});
|
807
|
-
const { entities
|
718
|
+
const { entities } = await this.priceListService_.upsertWithReplace(normalizedData, {
|
808
719
|
relations: ["price_list_rules"],
|
809
720
|
});
|
810
|
-
composeAllEvents({
|
811
|
-
eventBuilders: _utils_1.eventBuilders,
|
812
|
-
performedActions,
|
813
|
-
sharedContext,
|
814
|
-
});
|
815
721
|
return entities;
|
816
722
|
}
|
817
723
|
async updatePriceListPrices_(data, sharedContext = {}) {
|
@@ -830,12 +736,7 @@ class PricingModuleService extends BaseClass {
|
|
830
736
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Price list with id: ${priceListId} not found`);
|
831
737
|
}
|
832
738
|
}
|
833
|
-
const { entities
|
834
|
-
composeAllEvents({
|
835
|
-
eventBuilders: _utils_1.eventBuilders,
|
836
|
-
performedActions,
|
837
|
-
sharedContext,
|
838
|
-
});
|
739
|
+
const { entities } = await this.priceService_.upsertWithReplace(pricesToUpsert, { relations: ["price_rules"] }, sharedContext);
|
839
740
|
return entities;
|
840
741
|
}
|
841
742
|
async removePrices_(ids, sharedContext = {}) {
|
@@ -857,12 +758,7 @@ class PricingModuleService extends BaseClass {
|
|
857
758
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Price list with id: ${price.price_list_id} not found`);
|
858
759
|
}
|
859
760
|
});
|
860
|
-
const { entities
|
861
|
-
composeAllEvents({
|
862
|
-
eventBuilders: _utils_1.eventBuilders,
|
863
|
-
performedActions,
|
864
|
-
sharedContext,
|
865
|
-
});
|
761
|
+
const { entities } = await this.priceService_.upsertWithReplace(pricesToUpsert, { relations: ["price_rules"] }, sharedContext);
|
866
762
|
return entities;
|
867
763
|
}
|
868
764
|
async setPriceListRules_(data, sharedContext = {}) {
|
@@ -900,12 +796,7 @@ class PricingModuleService extends BaseClass {
|
|
900
796
|
};
|
901
797
|
})
|
902
798
|
.filter(Boolean);
|
903
|
-
const { entities
|
904
|
-
composeAllEvents({
|
905
|
-
eventBuilders: _utils_1.eventBuilders,
|
906
|
-
performedActions,
|
907
|
-
sharedContext,
|
908
|
-
});
|
799
|
+
const { entities } = await this.priceListService_.upsertWithReplace(priceListsUpsert, { relations: ["price_list_rules"] }, sharedContext);
|
909
800
|
return entities;
|
910
801
|
}
|
911
802
|
async removePriceListRules_(data, sharedContext = {}) {
|
@@ -945,12 +836,7 @@ class PricingModuleService extends BaseClass {
|
|
945
836
|
};
|
946
837
|
})
|
947
838
|
.filter(Boolean);
|
948
|
-
const { entities
|
949
|
-
composeAllEvents({
|
950
|
-
eventBuilders: _utils_1.eventBuilders,
|
951
|
-
performedActions,
|
952
|
-
sharedContext,
|
953
|
-
});
|
839
|
+
const { entities } = await this.priceListService_.upsertWithReplace(priceListsUpsert, { relations: ["price_list_rules"] }, sharedContext);
|
954
840
|
return entities;
|
955
841
|
}
|
956
842
|
normalizePriceListDate(data) {
|
@@ -975,6 +861,42 @@ class PricingModuleService extends BaseClass {
|
|
975
861
|
}
|
976
862
|
}
|
977
863
|
exports.default = PricingModuleService;
|
864
|
+
__decorate([
|
865
|
+
(0, utils_1.InjectTransactionManager)(),
|
866
|
+
(0, utils_1.EmitEvents)()
|
867
|
+
// @ts-expect-error
|
868
|
+
,
|
869
|
+
__metadata("design:type", Function),
|
870
|
+
__metadata("design:paramtypes", [Object]),
|
871
|
+
__metadata("design:returntype", Promise)
|
872
|
+
], PricingModuleService.prototype, "createPriceRules", null);
|
873
|
+
__decorate([
|
874
|
+
(0, utils_1.InjectTransactionManager)(),
|
875
|
+
(0, utils_1.EmitEvents)()
|
876
|
+
// @ts-expect-error
|
877
|
+
,
|
878
|
+
__metadata("design:type", Function),
|
879
|
+
__metadata("design:paramtypes", [Object]),
|
880
|
+
__metadata("design:returntype", Promise)
|
881
|
+
], PricingModuleService.prototype, "updatePriceRules", null);
|
882
|
+
__decorate([
|
883
|
+
(0, utils_1.InjectTransactionManager)(),
|
884
|
+
(0, utils_1.EmitEvents)()
|
885
|
+
// @ts-expect-error
|
886
|
+
,
|
887
|
+
__metadata("design:type", Function),
|
888
|
+
__metadata("design:paramtypes", [Object]),
|
889
|
+
__metadata("design:returntype", Promise)
|
890
|
+
], PricingModuleService.prototype, "createPriceListRules", null);
|
891
|
+
__decorate([
|
892
|
+
(0, utils_1.InjectTransactionManager)(),
|
893
|
+
(0, utils_1.EmitEvents)()
|
894
|
+
// @ts-expect-error
|
895
|
+
,
|
896
|
+
__metadata("design:type", Function),
|
897
|
+
__metadata("design:paramtypes", [Object]),
|
898
|
+
__metadata("design:returntype", Promise)
|
899
|
+
], PricingModuleService.prototype, "updatePriceListRules", null);
|
978
900
|
__decorate([
|
979
901
|
(0, utils_1.InjectManager)()
|
980
902
|
// @ts-expect-error
|
@@ -1001,6 +923,22 @@ __decorate([
|
|
1001
923
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
1002
924
|
__metadata("design:returntype", Promise)
|
1003
925
|
], PricingModuleService.prototype, "listAndCountPriceSets", null);
|
926
|
+
__decorate([
|
927
|
+
(0, utils_1.InjectManager)()
|
928
|
+
// @ts-expect-error
|
929
|
+
,
|
930
|
+
__metadata("design:type", Function),
|
931
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
932
|
+
__metadata("design:returntype", Promise)
|
933
|
+
], PricingModuleService.prototype, "listPriceRules", null);
|
934
|
+
__decorate([
|
935
|
+
(0, utils_1.InjectManager)()
|
936
|
+
// @ts-expect-error
|
937
|
+
,
|
938
|
+
__metadata("design:type", Function),
|
939
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
940
|
+
__metadata("design:returntype", Promise)
|
941
|
+
], PricingModuleService.prototype, "listPricePreferences", null);
|
1004
942
|
__decorate([
|
1005
943
|
(0, utils_1.InjectManager)(),
|
1006
944
|
__param(2, (0, utils_1.MedusaContext)()),
|
@@ -1026,6 +964,13 @@ __decorate([
|
|
1026
964
|
__metadata("design:paramtypes", [Object, Object]),
|
1027
965
|
__metadata("design:returntype", Promise)
|
1028
966
|
], PricingModuleService.prototype, "upsertPriceSets", null);
|
967
|
+
__decorate([
|
968
|
+
(0, utils_1.InjectTransactionManager)(),
|
969
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
970
|
+
__metadata("design:type", Function),
|
971
|
+
__metadata("design:paramtypes", [Object, Object]),
|
972
|
+
__metadata("design:returntype", Promise)
|
973
|
+
], PricingModuleService.prototype, "upsertPriceSets_", null);
|
1029
974
|
__decorate([
|
1030
975
|
(0, utils_1.InjectManager)(),
|
1031
976
|
(0, utils_1.EmitEvents)()
|
@@ -1062,7 +1007,7 @@ __decorate([
|
|
1062
1007
|
__metadata("design:returntype", Promise)
|
1063
1008
|
], PricingModuleService.prototype, "createPriceLists", null);
|
1064
1009
|
__decorate([
|
1065
|
-
(0, utils_1.
|
1010
|
+
(0, utils_1.InjectManager)(),
|
1066
1011
|
(0, utils_1.EmitEvents)()
|
1067
1012
|
// @ts-ignore
|
1068
1013
|
,
|
@@ -1128,7 +1073,15 @@ __decorate([
|
|
1128
1073
|
__metadata("design:returntype", Promise)
|
1129
1074
|
], PricingModuleService.prototype, "upsertPricePreferences", null);
|
1130
1075
|
__decorate([
|
1131
|
-
(0, utils_1.
|
1076
|
+
(0, utils_1.InjectTransactionManager)(),
|
1077
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
1078
|
+
__metadata("design:type", Function),
|
1079
|
+
__metadata("design:paramtypes", [Object, Object]),
|
1080
|
+
__metadata("design:returntype", Promise)
|
1081
|
+
], PricingModuleService.prototype, "upsertPricePreferences_", null);
|
1082
|
+
__decorate([
|
1083
|
+
(0, utils_1.InjectManager)(),
|
1084
|
+
(0, utils_1.EmitEvents)()
|
1132
1085
|
// @ts-expect-error
|
1133
1086
|
,
|
1134
1087
|
__param(2, (0, utils_1.MedusaContext)()),
|
@@ -1208,20 +1161,6 @@ __decorate([
|
|
1208
1161
|
__metadata("design:paramtypes", [Array, Object]),
|
1209
1162
|
__metadata("design:returntype", Promise)
|
1210
1163
|
], PricingModuleService.prototype, "removePriceListRules_", null);
|
1211
|
-
const composeAllEvents = ({ eventBuilders, performedActions, sharedContext, }) => {
|
1212
|
-
for (const action of Object.keys(performedActions)) {
|
1213
|
-
for (const entity of Object.keys(performedActions[action])) {
|
1214
|
-
const eventName = action + (0, utils_1.upperCaseFirst)(entity);
|
1215
|
-
if (!eventBuilders[eventName]) {
|
1216
|
-
continue;
|
1217
|
-
}
|
1218
|
-
eventBuilders[eventName]({
|
1219
|
-
data: performedActions[action][entity] ?? [],
|
1220
|
-
sharedContext,
|
1221
|
-
});
|
1222
|
-
}
|
1223
|
-
}
|
1224
|
-
};
|
1225
1164
|
const isTaxInclusive = (priceRules, preferences, currencyCode, regionId) => {
|
1226
1165
|
const regionRule = priceRules?.find((rule) => rule.attribute === "region_id" && rule.value === regionId);
|
1227
1166
|
const regionPreference = preferences.find((p) => p.attribute === "region_id" && p.value === regionId);
|