cloudcommerce 0.0.54 → 0.0.57
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 +22 -0
- package/package.json +6 -6
- package/packages/api/lib/index.js +14 -3
- package/packages/api/lib/index.js.map +1 -1
- package/packages/api/lib/types.d.ts +1 -1
- package/packages/api/package.json +1 -1
- package/packages/api/src/index.ts +14 -3
- package/packages/api/src/types.ts +1 -1
- package/packages/apps/discounts/lib/discounts.d.ts +1 -1
- package/packages/apps/discounts/lib/discounts.js +2 -3
- package/packages/apps/discounts/lib/discounts.js.map +1 -1
- package/packages/apps/discounts/lib-cjs/apply-discount.cjs +330 -0
- package/packages/apps/discounts/lib-cjs/helpers.cjs +167 -0
- package/packages/apps/discounts/package.json +2 -1
- package/packages/apps/discounts/src/discounts.ts +2 -3
- package/packages/cli/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/lib/config.d.ts +5 -0
- package/packages/firebase/lib/config.js +8 -0
- package/packages/firebase/lib/config.js.map +1 -1
- package/packages/firebase/lib/handlers/check-store-events.js +92 -15
- package/packages/firebase/lib/handlers/check-store-events.js.map +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/firebase/src/config.ts +9 -0
- package/packages/firebase/src/handlers/check-store-events.ts +98 -18
- package/packages/modules/lib/firebase/call-app-module.js +36 -2
- package/packages/modules/lib/firebase/call-app-module.js.map +1 -1
- package/packages/modules/lib/firebase/handle-module.js +6 -1
- package/packages/modules/lib/firebase/handle-module.js.map +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/modules/src/firebase/call-app-module.ts +37 -3
- package/packages/modules/src/firebase/handle-module.ts +6 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/storefront/package.json +4 -4
- package/packages/types/index.ts +4 -1
- package/packages/types/package.json +1 -1
- package/packages/firebase/lib/types.d.ts +0 -6
- package/packages/firebase/lib/types.js +0 -2
- package/packages/firebase/lib/types.js.map +0 -1
- package/packages/firebase/src/types.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.57](https://github.com/ecomplus/cloud-commerce/compare/v0.0.56...v0.0.57) (2022-08-23)
|
|
6
|
+
|
|
7
|
+
### [0.0.56](https://github.com/ecomplus/cloud-commerce/compare/v0.0.55...v0.0.56) (2022-08-23)
|
|
8
|
+
|
|
9
|
+
### [0.0.55](https://github.com/ecomplus/cloud-commerce/compare/v0.0.54...v0.0.55) (2022-08-23)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* Also fetch customers resource events on Store API ([15fb1ec](https://github.com/ecomplus/cloud-commerce/commit/15fb1ec63641d768f7275f91269c99be6812bcea))
|
|
15
|
+
* **api:** Properly handle params fields as array of strings or numbers ([b66f688](https://github.com/ecomplus/cloud-commerce/commit/b66f6884baa0d26b0a3859a35eee41697a90ff64))
|
|
16
|
+
* **discounts:** Move discounts app handlers from https://github.com/ecomplus/discounts ([12f5aa3](https://github.com/ecomplus/cloud-commerce/commit/12f5aa3ef29a0faa787f4af55634cf15097d9c11))
|
|
17
|
+
* **events:** Start parsing events topics and checking active subscribers apps ([7a3aff1](https://github.com/ecomplus/cloud-commerce/commit/7a3aff17bc2d19c171d95fd3a1c5704927081376))
|
|
18
|
+
* **modules:** Check middleware functions on global scope for internal modules [[#29](https://github.com/ecomplus/cloud-commerce/issues/29)] ([8324659](https://github.com/ecomplus/cloud-commerce/commit/83246597059bedc74efafc3949d66430d383e58b))
|
|
19
|
+
* **types:** Enum new events topics ([9e154d7](https://github.com/ecomplus/cloud-commerce/commit/9e154d7154ef86b952d29ba661cf15a0345f82c6))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **deps:** Update all non-major dependencies ([#44](https://github.com/ecomplus/cloud-commerce/issues/44)) ([23a0c07](https://github.com/ecomplus/cloud-commerce/commit/23a0c07fb8fc0961a53f6319cf76f9a6657f88ff))
|
|
25
|
+
* **modules:** Catch internal module functions (or midd) errors ([b162d8d](https://github.com/ecomplus/cloud-commerce/commit/b162d8d190b8616a190e6d9db0f7cdb309dfa7a2))
|
|
26
|
+
|
|
5
27
|
### [0.0.54](https://github.com/ecomplus/cloud-commerce/compare/v0.0.53...v0.0.54) (2022-08-19)
|
|
6
28
|
|
|
7
29
|
### [0.0.53](https://github.com/ecomplus/cloud-commerce/compare/v0.0.52...v0.0.53) (2022-08-19)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcommerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.57",
|
|
5
5
|
"description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
|
|
6
6
|
"main": "packages/api/lib/index.js",
|
|
7
7
|
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"@commitlint/config-conventional": "^17.0.3",
|
|
21
21
|
"@commitlint/rules": "^17.0.0",
|
|
22
22
|
"@types/node": "^18.0.5",
|
|
23
|
-
"@typescript-eslint/eslint-plugin": "^5.33.
|
|
24
|
-
"@typescript-eslint/parser": "^5.33.
|
|
25
|
-
"esbuild": "^0.15.
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
24
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
25
|
+
"esbuild": "^0.15.5",
|
|
26
26
|
"eslint": "^8.22.0",
|
|
27
27
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
28
28
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"standard-version": "^9.5.0",
|
|
33
33
|
"turbo": "^1.4.3",
|
|
34
34
|
"typescript": "^4.7.4",
|
|
35
|
-
"vite": "^3.0.
|
|
36
|
-
"vitest": "^0.
|
|
35
|
+
"vite": "^3.0.9",
|
|
36
|
+
"vitest": "^0.22.1",
|
|
37
37
|
"zx": "^7.0.8"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
@@ -49,9 +49,20 @@ const def = {
|
|
|
49
49
|
if (params) {
|
|
50
50
|
if (typeof params === 'string') {
|
|
51
51
|
url += `?${params}`;
|
|
52
|
-
} else {
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
} else if (typeof params === 'object') {
|
|
53
|
+
const searchParams = new URLSearchParams();
|
|
54
|
+
Object.keys(params).forEach((key) => {
|
|
55
|
+
const values = params[key];
|
|
56
|
+
if (Array.isArray(values)) {
|
|
57
|
+
values.forEach((value) => {
|
|
58
|
+
// https://github.com/microsoft/TypeScript/issues/32951
|
|
59
|
+
searchParams.append(key, value);
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
searchParams.append(key, values);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
url += `?${searchParams.toString()}`;
|
|
55
66
|
}
|
|
56
67
|
}
|
|
57
68
|
return { url, headers };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,aAAa;AACb,MAAM,GAAG,GAA8B,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC;OACxE,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;OACvD,EAAE,CAAC;AAER,MAAM,QAAS,SAAQ,KAAK;IAM1B,YACE,MAAc,EACd,QAA+B,EAC/B,GAAY,EACZ,YAAqB,KAAK;QAE1B,IAAI,QAAQ,EAAE;YACZ,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAC3B,I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KAAK,GAAG,CAAC,QAAkB,EAAE,IAAS,EAAE,MAA4B,EAAE,EAAE,CAAC,GAAG,CAAC;IACjF,GAAG,MAAM;IACT,MAAM,EAAE,OAAO;IACf,QAAQ;IACR,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,MAA4B,EAAE,EAAE,CAAC,GAAG,CAAC;IACpE,GAAG,MAAM;IACT,MAAM,EAAE,QAAQ;IAChB,QAAQ;CACT,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;AAChB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAClB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;AAEjB,eAAe,GAAG,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,EACH,QAAQ,GACT,CAAC"}
|
|
@@ -27,7 +27,7 @@ declare type Config = {
|
|
|
27
27
|
lang?: string;
|
|
28
28
|
method?: Method;
|
|
29
29
|
endpoint: Endpoint;
|
|
30
|
-
params?: Record<string, string | number | boolean
|
|
30
|
+
params?: Record<string, string | number | boolean | string[] | number[]> | string;
|
|
31
31
|
headers?: Headers | Record<string, string>;
|
|
32
32
|
timeout?: number;
|
|
33
33
|
maxRetries?: number;
|
|
@@ -72,9 +72,20 @@ const def = {
|
|
|
72
72
|
if (params) {
|
|
73
73
|
if (typeof params === 'string') {
|
|
74
74
|
url += `?${params}`;
|
|
75
|
-
} else {
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
} else if (typeof params === 'object') {
|
|
76
|
+
const searchParams = new URLSearchParams();
|
|
77
|
+
Object.keys(params).forEach((key) => {
|
|
78
|
+
const values = params[key];
|
|
79
|
+
if (Array.isArray(values)) {
|
|
80
|
+
values.forEach((value: string | number) => {
|
|
81
|
+
// https://github.com/microsoft/TypeScript/issues/32951
|
|
82
|
+
searchParams.append(key, value as string);
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
searchParams.append(key, values as string);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
url += `?${searchParams.toString()}`;
|
|
78
89
|
}
|
|
79
90
|
}
|
|
80
91
|
return { url, headers };
|
|
@@ -56,7 +56,7 @@ type Config = {
|
|
|
56
56
|
lang?: string,
|
|
57
57
|
method?: Method,
|
|
58
58
|
endpoint: Endpoint,
|
|
59
|
-
params?: Record<string, string | number | boolean
|
|
59
|
+
params?: Record<string, string | number | boolean | string[] | number[]> | string,
|
|
60
60
|
headers?: Headers | Record<string, string>,
|
|
61
61
|
timeout?: number,
|
|
62
62
|
maxRetries?: number,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { AppModuleBody } from '@cloudcommerce/types';
|
|
2
|
-
export declare const applyDiscount: (modBody: AppModuleBody) => Promise<
|
|
2
|
+
export declare const applyDiscount: (modBody: AppModuleBody) => Promise<any>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as handleApplyDiscount from '../lib-cjs/apply-discount.cjs';
|
|
2
2
|
|
|
3
3
|
export const applyDiscount = async (modBody) => {
|
|
4
|
-
|
|
5
|
-
return {};
|
|
4
|
+
return handleApplyDiscount(modBody);
|
|
6
5
|
};
|
|
7
6
|
// # sourceMappingURL=discounts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discounts.js","sourceRoot":"","sources":["../src/discounts.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"discounts.js","sourceRoot":"","sources":["../src/discounts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,mBAAmB,MAAM,+BAA+B,CAAC;AAErE,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAC5D,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
const ecomUtils = require('@ecomplus/utils');
|
|
2
|
+
const api = require('@cloudcommerce/api');
|
|
3
|
+
const getEnv = require('@cloudcommerce/firebase/lib/env');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
validateDateRange,
|
|
7
|
+
validateCustomerId,
|
|
8
|
+
checkOpenPromotion,
|
|
9
|
+
getValidDiscountRules,
|
|
10
|
+
matchDiscountRule,
|
|
11
|
+
checkCampaignProducts,
|
|
12
|
+
} = require('./helpers.cjs');
|
|
13
|
+
|
|
14
|
+
module.exports = async ({ params, application }) => {
|
|
15
|
+
// app configured options
|
|
16
|
+
const config = {
|
|
17
|
+
...application.data,
|
|
18
|
+
...application.hidden_data,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// setup response object
|
|
22
|
+
// https://apx-mods.e-com.plus/api/v1/apply_discount/response_schema.json?store_id=100
|
|
23
|
+
const response = {};
|
|
24
|
+
const respondSuccess = () => {
|
|
25
|
+
if (response.available_extra_discount && !response.available_extra_discount.value) {
|
|
26
|
+
delete response.available_extra_discount;
|
|
27
|
+
}
|
|
28
|
+
if (
|
|
29
|
+
response.discount_rule
|
|
30
|
+
&& (!response.discount_rule.extra_discount || !response.discount_rule.extra_discount.value)
|
|
31
|
+
) {
|
|
32
|
+
delete response.discount_rule;
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const addDiscount = (discount, flag, label) => {
|
|
38
|
+
let value;
|
|
39
|
+
const maxDiscount = params.amount[discount.apply_at || 'total'];
|
|
40
|
+
if (maxDiscount) {
|
|
41
|
+
// update amount discount and total
|
|
42
|
+
if (discount.type === 'percentage') {
|
|
43
|
+
value = maxDiscount * (discount.value / 100);
|
|
44
|
+
} else {
|
|
45
|
+
value = discount.value;
|
|
46
|
+
}
|
|
47
|
+
if (value > maxDiscount) {
|
|
48
|
+
value = maxDiscount;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (value) {
|
|
53
|
+
if (response.discount_rule) {
|
|
54
|
+
// accumulate discount
|
|
55
|
+
const extraDiscount = response.discount_rule.extra_discount;
|
|
56
|
+
extraDiscount.value += value;
|
|
57
|
+
if (extraDiscount.flags.length < 20) {
|
|
58
|
+
extraDiscount.flags.push(flag);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
response.discount_rule = {
|
|
62
|
+
label: label || flag,
|
|
63
|
+
extra_discount: {
|
|
64
|
+
value,
|
|
65
|
+
flags: [flag],
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (params.items && params.items.length) {
|
|
75
|
+
// try product kit discounts first
|
|
76
|
+
if (Array.isArray(config.product_kit_discounts)) {
|
|
77
|
+
config.product_kit_discounts = config.product_kit_discounts.map((kitDiscount) => {
|
|
78
|
+
if (!kitDiscount.product_ids) {
|
|
79
|
+
// kit with any items
|
|
80
|
+
kitDiscount.product_ids = [];
|
|
81
|
+
}
|
|
82
|
+
return kitDiscount;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const kitDiscounts = getValidDiscountRules(config.product_kit_discounts, params, params.items)
|
|
86
|
+
.sort((a, b) => {
|
|
87
|
+
if (a.min_quantity > b.min_quantity) {
|
|
88
|
+
return -1;
|
|
89
|
+
}
|
|
90
|
+
if (b.min_quantity > a.min_quantity) {
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
if (a.discount.min_amount > b.discount.min_amount) {
|
|
94
|
+
return -1;
|
|
95
|
+
}
|
|
96
|
+
if (b.discount.min_amount > a.discount.min_amount) {
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
return 0;
|
|
100
|
+
});
|
|
101
|
+
// prevent applying duplicated kit discount for same items
|
|
102
|
+
let discountedItemIds = [];
|
|
103
|
+
|
|
104
|
+
kitDiscounts.forEach((kitDiscount, index) => {
|
|
105
|
+
if (kitDiscount) {
|
|
106
|
+
const productIds = Array.isArray(kitDiscount.product_ids)
|
|
107
|
+
? kitDiscount.product_ids
|
|
108
|
+
: [];
|
|
109
|
+
let kitItems = productIds.length
|
|
110
|
+
? params.items.filter((item) => item.quantity && productIds.indexOf(item.product_id) > -1)
|
|
111
|
+
: params.items;
|
|
112
|
+
kitItems = kitItems.filter((item) => discountedItemIds.indexOf(item._id) === -1);
|
|
113
|
+
if (kitDiscount.min_quantity > 0) {
|
|
114
|
+
// check total items quantity
|
|
115
|
+
let totalQuantity = 0;
|
|
116
|
+
kitItems.forEach(({ quantity }) => {
|
|
117
|
+
totalQuantity += quantity;
|
|
118
|
+
});
|
|
119
|
+
if (totalQuantity < kitDiscount.min_quantity) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (kitDiscount.discount.type === 'fixed' && kitDiscount.cumulative_discount !== false) {
|
|
123
|
+
kitDiscount.discount.value *= Math.floor(totalQuantity / kitDiscount.min_quantity);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!params.amount || !(kitDiscount.discount.min_amount > params.amount.total)) {
|
|
128
|
+
if (kitDiscount.check_all_items !== false) {
|
|
129
|
+
for (let i = 0; i < productIds.length; i++) {
|
|
130
|
+
const productId = productIds[i];
|
|
131
|
+
if (productId
|
|
132
|
+
&& !kitItems.find((item) => item.quantity && item.product_id === productId)) {
|
|
133
|
+
// product not on current cart
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// apply cumulative discount \o/
|
|
139
|
+
addDiscount(kitDiscount.discount, `KIT-${(index + 1)}`, kitDiscount.label);
|
|
140
|
+
discountedItemIds = discountedItemIds.concat(kitItems.map((item) => item.product_id));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// gift products (freebies) campaings
|
|
146
|
+
if (Array.isArray(config.freebies_rules)) {
|
|
147
|
+
const validFreebiesRules = config.freebies_rules.filter((rule) => {
|
|
148
|
+
return validateDateRange(rule)
|
|
149
|
+
&& validateCustomerId(rule, params)
|
|
150
|
+
&& checkCampaignProducts(rule.check_product_ids, params)
|
|
151
|
+
&& Array.isArray(rule.product_ids)
|
|
152
|
+
&& rule.product_ids.length;
|
|
153
|
+
});
|
|
154
|
+
if (validFreebiesRules) {
|
|
155
|
+
let subtotal = 0;
|
|
156
|
+
params.items.forEach((item) => {
|
|
157
|
+
subtotal += (item.quantity * ecomUtils.price(item));
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
let bestRule;
|
|
161
|
+
let discountValue = 0;
|
|
162
|
+
for (let i = 0; i < validFreebiesRules.length; i++) {
|
|
163
|
+
const rule = validFreebiesRules[i];
|
|
164
|
+
// start calculating discount
|
|
165
|
+
let value = 0;
|
|
166
|
+
rule.product_ids.forEach((productId) => {
|
|
167
|
+
const item = params.items.find((item) => productId === item.product_id);
|
|
168
|
+
if (item) {
|
|
169
|
+
value += ecomUtils.price(item);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
const fixedSubtotal = subtotal - value;
|
|
173
|
+
if (!bestRule || value > discountValue || bestRule.min_subtotal < rule.min_subtotal) {
|
|
174
|
+
if (!(rule.min_subtotal > fixedSubtotal)) {
|
|
175
|
+
bestRule = rule;
|
|
176
|
+
discountValue = value;
|
|
177
|
+
} else if (!discountValue && subtotal >= rule.min_subtotal) {
|
|
178
|
+
// discount not applicable yet but additional freebies are available
|
|
179
|
+
bestRule = rule;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (bestRule) {
|
|
185
|
+
// provide freebie products \o/
|
|
186
|
+
response.freebie_product_ids = bestRule.product_ids;
|
|
187
|
+
if (discountValue) {
|
|
188
|
+
addDiscount(
|
|
189
|
+
{
|
|
190
|
+
type: 'fixed',
|
|
191
|
+
value: discountValue,
|
|
192
|
+
},
|
|
193
|
+
'FREEBIES',
|
|
194
|
+
bestRule.label,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const discountRules = getValidDiscountRules(config.discount_rules, params);
|
|
203
|
+
if (discountRules.length) {
|
|
204
|
+
const { discountRule, discountMatchEnum } = matchDiscountRule(discountRules, params);
|
|
205
|
+
if (discountRule) {
|
|
206
|
+
if (!checkCampaignProducts(discountRule.product_ids, params)) {
|
|
207
|
+
return {
|
|
208
|
+
available_extra_discount: response.available_extra_discount,
|
|
209
|
+
invalid_coupon_message: params.lang === 'pt_br'
|
|
210
|
+
? 'Nenhum produto da promoção está incluído no carrinho'
|
|
211
|
+
: 'No promotion products are included in the cart',
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const excludedProducts = discountRule.excluded_product_ids;
|
|
216
|
+
if (Array.isArray(excludedProducts) && excludedProducts.length && params.items) {
|
|
217
|
+
// must check any excluded product is on cart
|
|
218
|
+
for (let i = 0; i < params.items.length; i++) {
|
|
219
|
+
const item = params.items[i];
|
|
220
|
+
if (item.quantity && excludedProducts.includes(item.product_id)) {
|
|
221
|
+
return {
|
|
222
|
+
available_extra_discount: response.available_extra_discount,
|
|
223
|
+
invalid_coupon_message: params.lang === 'pt_br'
|
|
224
|
+
? `Promoção é inválida para o produto ${item.name}`
|
|
225
|
+
: `Invalid promotion for product ${item.name}`,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let { label } = discountRule;
|
|
232
|
+
const { discount } = discountRule;
|
|
233
|
+
if (typeof label !== 'string' || !label) {
|
|
234
|
+
label = params.discount_coupon || `DISCOUNT ${discountMatchEnum}`;
|
|
235
|
+
}
|
|
236
|
+
if (
|
|
237
|
+
discount.apply_at !== 'freight'
|
|
238
|
+
&& (!response.available_extra_discount || !response.available_extra_discount.value
|
|
239
|
+
|| discountRule.default_discount === true || checkOpenPromotion(discountRule))
|
|
240
|
+
) {
|
|
241
|
+
// show current discount rule as available discount to apply
|
|
242
|
+
response.available_extra_discount = {
|
|
243
|
+
label: label.substring(0, 50),
|
|
244
|
+
};
|
|
245
|
+
['min_amount', 'type', 'value'].forEach((field) => {
|
|
246
|
+
if (discount[field]) {
|
|
247
|
+
response.available_extra_discount[field] = discount[field];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// params object follows list payments request schema:
|
|
253
|
+
// https://apx-mods.e-com.plus/api/v1/apply_discount/schema.json?store_id=100
|
|
254
|
+
if (
|
|
255
|
+
params.amount && params.amount.total > 0
|
|
256
|
+
&& !(discountRule.discount.min_amount > params.amount[discountRule.discount.amount_field || 'total'])
|
|
257
|
+
) {
|
|
258
|
+
if (
|
|
259
|
+
discountRule.cumulative_discount === false
|
|
260
|
+
&& (response.discount_rule || params.amount.discount)
|
|
261
|
+
) {
|
|
262
|
+
// explain discount can't be applied :(
|
|
263
|
+
// https://apx-mods.e-com.plus/api/v1/apply_discount/response_schema.json?store_id=100
|
|
264
|
+
return {
|
|
265
|
+
invalid_coupon_message: params.lang === 'pt_br'
|
|
266
|
+
? 'A promoção não pôde ser aplicada porque este desconto não é cumulativo'
|
|
267
|
+
: 'This discount is not cumulative',
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// we have a discount to apply \o/
|
|
272
|
+
if (addDiscount(discountRule.discount, discountMatchEnum)) {
|
|
273
|
+
// add discount label and description if any
|
|
274
|
+
response.discount_rule.label = label;
|
|
275
|
+
if (discountRule.description) {
|
|
276
|
+
response.discount_rule.description = discountRule.description;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const { customer } = params;
|
|
280
|
+
if (
|
|
281
|
+
customer && customer._id
|
|
282
|
+
&& (discountRule.usage_limit > 0 || discountRule.total_usage_limit > 0)
|
|
283
|
+
) {
|
|
284
|
+
// list orders to check discount usage limits
|
|
285
|
+
// eslint-disable-next-line prefer-template
|
|
286
|
+
const endpoint = 'orders?fields=_id'
|
|
287
|
+
+ `&extra_discount.app.label${(discountRule.case_insensitive ? '%=' : '=')}`
|
|
288
|
+
+ encodeURIComponent(label);
|
|
289
|
+
const usageLimits = [{
|
|
290
|
+
// limit by customer
|
|
291
|
+
query: `&buyers._id=${customer._id}`,
|
|
292
|
+
max: discountRule.usage_limit,
|
|
293
|
+
}, {
|
|
294
|
+
// total limit
|
|
295
|
+
query: '',
|
|
296
|
+
max: discountRule.total_usage_limit,
|
|
297
|
+
}];
|
|
298
|
+
const { apiAuth } = getEnv();
|
|
299
|
+
for (let i = 0; i < usageLimits.length; i++) {
|
|
300
|
+
const { query, max } = usageLimits[i];
|
|
301
|
+
if (max) {
|
|
302
|
+
let countOrders;
|
|
303
|
+
try {
|
|
304
|
+
// send Store API request to list orders with filters
|
|
305
|
+
const { data } = await api.get(`${endpoint}${query}`, { apiAuth });
|
|
306
|
+
countOrders = data.result.length;
|
|
307
|
+
} catch (e) {
|
|
308
|
+
countOrders = max;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (countOrders >= max) {
|
|
312
|
+
// limit reached
|
|
313
|
+
return {
|
|
314
|
+
invalid_coupon_message: params.lang === 'pt_br'
|
|
315
|
+
? 'A promoção não pôde ser aplicada porque já atingiu o limite de usos'
|
|
316
|
+
: 'The promotion could not be applied because it has already reached the usage limit',
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return respondSuccess();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// response with no error nor discount applied
|
|
329
|
+
return respondSuccess();
|
|
330
|
+
};
|