@nuskin/ns-product-lib 2.5.0-cx24-2467.3.1 → 2.5.0-cx24-2179.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- # [2.5.0-cx24-2467.3.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-CX24.2.1...v2.5.0-cx24-2467.3.1) (2022-11-22)
1
+ # [2.5.0-cx24-2179.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-CX24.2.1...v2.5.0-cx24-2179.2.1) (2022-12-02)
2
2
 
3
3
 
4
4
  ### Fix
@@ -7,7 +7,7 @@
7
7
 
8
8
  ### New
9
9
 
10
- * exclude base sku in variants (#CX24-2467) ([e20697b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e20697b815e9001ec3ae888eeb9e005f88798056)), closes [#CX24-2467](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2467)
10
+ * added eq promotion support (#CX24-2179) ([bc7782d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bc7782dcc2b6db84bd4203ea64e60d80b55e4bcd)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
11
11
 
12
12
  ### Release
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.5.0-cx24-2467.3.1",
3
+ "version": "2.5.0-cx24-2179.2.1",
4
4
  "description": "This project contains shared Product models and code between the backend and frontend.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -91,7 +91,7 @@ const ProductData = {
91
91
 
92
92
  /**
93
93
  * Map product variant
94
- * @todo remove unnecessary fields
94
+ * @todo remove unnecessary fields and do code refactoring
95
95
  * @param {*} eqVariant
96
96
  * @returns Array<Product>
97
97
  */
@@ -107,6 +107,10 @@ const ProductData = {
107
107
  thumbnailImage = imageURL.replace(regex,'40.40')
108
108
  }
109
109
 
110
+ const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(eqVariant);
111
+ const productPrice = eventName ? defaultProductPrice : eqVariant.priceFacets["Regular Price"];
112
+ const wrtlPrice = eventName ? computedPrice : eqVariant.priceFacets["Regular Price"];
113
+
110
114
  return {
111
115
  "sku": eqVariant.identifier,
112
116
  "globalProductID": eqVariant.identifier,
@@ -145,9 +149,9 @@ const ProductData = {
145
149
  "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
146
150
  "pv":eqVariant.priceFacets.PV,
147
151
  "priceType": "WRTL",
148
- "price": eqVariant.priceFacets["Regular Price"],
152
+ "price": productPrice,
149
153
  "priceMap": {
150
- "WRTL": eqVariant.priceFacets["Regular Price"],
154
+ "WRTL": wrtlPrice,
151
155
  "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
152
156
  "WADR": eqVariant.priceFacets["Regular Price"],
153
157
  "RTL": eqVariant.priceFacets["Regular Price"],
@@ -181,9 +185,9 @@ const ProductData = {
181
185
  "variantsLabel": eqVariant.properties.variantLabel || "",
182
186
  "groupOffer": false,
183
187
  "personalOffer": false,
184
- "savedEventName": null,
185
- "salesLabel": "",
186
- "eventName": null,
188
+ "savedEventName": eventName,
189
+ "salesLabel": eventLabels,
190
+ "eventName": eventName,
187
191
  "sizeWeight": '',
188
192
  "nettoWeight": "",
189
193
  "searchScore": 0,
@@ -198,6 +202,41 @@ const ProductData = {
198
202
  };
199
203
  },
200
204
 
205
+ /**
206
+ * Get EQ product promotions
207
+ * @param {*} product
208
+ * @returns {obj} promotion
209
+ */
210
+ getEqProductPromotions(product) {
211
+
212
+ if (!Array.isArray(product.promotion)) {
213
+ return {
214
+ eventLabels: "",
215
+ computedPrice : 0,
216
+ defaultProductPrice: product.priceFacets ? product.priceFacets["Regular Price"] : 0,
217
+ eventName: null
218
+ }
219
+ }
220
+
221
+ const defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
222
+ const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount ? product.totalValue.priceAfterDiscount : 0;
223
+ let eventName = "";
224
+ const eventLabels = [];
225
+
226
+ product.promotion.map(promotion => {
227
+ eventName = promotion.offerId;
228
+ eventLabels.push(promotion.message);
229
+ return promotion;
230
+ });
231
+
232
+ return {
233
+ eventLabels: eventLabels.join(','),
234
+ defaultProductPrice,
235
+ computedPrice,
236
+ eventName
237
+ }
238
+ },
239
+
201
240
  eqProductMapper: function (productDataResponse, skus) {
202
241
  let prod = [];
203
242
  let count = 0;
@@ -215,13 +254,17 @@ const ProductData = {
215
254
  }
216
255
 
217
256
  if (data.sku && data.sku.length > 1) {
218
- data.sku.filter(variant => variant.sku.substring(2, 4) !== "55")
219
- .map(variant => {
220
- variants[variant.identifier] = this.eqProductVariantMapper(variant);
221
- return variant;
222
- });
257
+ //exclude base product from variants
258
+ data.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
259
+ variants[variant.identifier] = this.eqProductVariantMapper(variant);
260
+ return variant;
261
+ });
223
262
  }
224
263
 
264
+ const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(data.sku[count]);
265
+ const productPrice = eventName ? defaultProductPrice : data.sku[count].priceFacets["Regular Price"];
266
+ const wrtlPrice = eventName ? computedPrice : data.sku[count].priceFacets["Regular Price"];
267
+
225
268
  prod = {
226
269
  "sku": data.sku[count].identifier,
227
270
  "globalProductID": data.identifier,
@@ -260,9 +303,9 @@ const ProductData = {
260
303
  "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
261
304
  "pv": data.sku[count].priceFacets.PV,
262
305
  "priceType": "WRTL",
263
- "price": data.sku[count].priceFacets["Regular Price"],
306
+ "price": productPrice,
264
307
  "priceMap": {
265
- "WRTL": data.sku[count].priceFacets["Regular Price"],
308
+ "WRTL": wrtlPrice,
266
309
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
267
310
  "WADR": data.sku[count].priceFacets["Regular Price"],
268
311
  "RTL": data.sku[count].priceFacets["Regular Price"],
@@ -298,9 +341,9 @@ const ProductData = {
298
341
  "variantsLabel": data.sku[count].properties.variantLabel || "",
299
342
  "groupOffer": false,
300
343
  "personalOffer": false,
301
- "savedEventName": null,
302
- "salesLabel": "",
303
- "eventName": null,
344
+ "savedEventName": eventName,
345
+ "salesLabel": eventLabels,
346
+ "eventName": eventName,
304
347
  "sizeWeight": '',
305
348
  "nettoWeight": "",
306
349
  "variants": variants,