@cloudcommerce/app-discounts 0.14.1 → 0.15.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/.turbo/turbo-build.log +1 -1
- package/lib-mjs/apply-discount.mjs +27 -2
- package/lib-mjs/helpers.mjs +4 -2
- package/package.json +4 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -344,10 +344,33 @@ export default async ({ params, application }) => {
|
|
|
344
344
|
if (discountRule.description) {
|
|
345
345
|
response.discount_rule.description = discountRule.description;
|
|
346
346
|
}
|
|
347
|
+
if (!checkOpenPromotion(discountRule)) {
|
|
348
|
+
// check for additional open discount
|
|
349
|
+
const {
|
|
350
|
+
discountRule: openDiscountRule,
|
|
351
|
+
discountMatchEnum: openDiscountMatchEnum,
|
|
352
|
+
} = matchDiscountRule(discountRules, {});
|
|
353
|
+
if (
|
|
354
|
+
openDiscountRule
|
|
355
|
+
&& openDiscountRule.cumulative_discount !== false
|
|
356
|
+
&& openDiscountRule.discount.min_amount
|
|
357
|
+
) {
|
|
358
|
+
let checkAmount = params.amount[openDiscountRule.discount.amount_field || 'total'];
|
|
359
|
+
if (checkAmount) {
|
|
360
|
+
// subtract current discount to validate cumulative open discount min amount
|
|
361
|
+
if (response.discount_rule) {
|
|
362
|
+
checkAmount -= response.discount_rule.extra_discount.value;
|
|
363
|
+
}
|
|
364
|
+
if (openDiscountRule.discount.min_amount <= checkAmount) {
|
|
365
|
+
addDiscount(openDiscountRule.discount, openDiscountMatchEnum);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
347
370
|
|
|
348
371
|
const { customer } = params;
|
|
349
372
|
if (
|
|
350
|
-
customer && customer._id
|
|
373
|
+
customer && (customer._id || customer.doc_number)
|
|
351
374
|
&& (discountRule.usage_limit > 0 || discountRule.total_usage_limit > 0)
|
|
352
375
|
) {
|
|
353
376
|
// list orders to check discount usage limits
|
|
@@ -357,7 +380,9 @@ export default async ({ params, application }) => {
|
|
|
357
380
|
+ encodeURIComponent(label);
|
|
358
381
|
const usageLimits = [{
|
|
359
382
|
// limit by customer
|
|
360
|
-
query:
|
|
383
|
+
query: customer.doc_number
|
|
384
|
+
? `&buyers.doc_number=${customer.doc_number}`
|
|
385
|
+
: `&buyers._id=${customer._id}`,
|
|
361
386
|
max: discountRule.usage_limit,
|
|
362
387
|
}, {
|
|
363
388
|
// total limit
|
package/lib-mjs/helpers.mjs
CHANGED
|
@@ -65,8 +65,10 @@ const getValidDiscountRules = (discountRules, params, items) => {
|
|
|
65
65
|
if (rule.discount && rule.discount.value) {
|
|
66
66
|
if (rule.discount.type === 'percentage') {
|
|
67
67
|
value *= rule.discount.value / 100;
|
|
68
|
+
} else if (rule.discount_kit_subtotal) {
|
|
69
|
+
value = rule.discount.value;
|
|
68
70
|
} else {
|
|
69
|
-
value
|
|
71
|
+
value = Math.min(value, rule.discount.value);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
rule.discount = {
|
|
@@ -88,7 +90,7 @@ const getValidDiscountRules = (discountRules, params, items) => {
|
|
|
88
90
|
return [];
|
|
89
91
|
};
|
|
90
92
|
|
|
91
|
-
const matchDiscountRule = (discountRules, params) => {
|
|
93
|
+
const matchDiscountRule = (discountRules, params = {}) => {
|
|
92
94
|
// try to match a promotion
|
|
93
95
|
if (params.discount_coupon) {
|
|
94
96
|
// match only by discount coupon
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-discounts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce app for complex discount rules",
|
|
6
6
|
"main": "lib/discounts.js",
|
|
7
7
|
"repository": {
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/discounts#readme",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ecomplus/utils": "1.5.0-rc.
|
|
20
|
-
"@cloudcommerce/api": "0.
|
|
19
|
+
"@ecomplus/utils": "1.5.0-rc.5",
|
|
20
|
+
"@cloudcommerce/api": "0.15.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@cloudcommerce/types": "0.
|
|
23
|
+
"@cloudcommerce/types": "0.15.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "bash ../../../scripts/build-lib.sh"
|