@nuskin/ns-product-lib 2.5.0-cx24-2179.1 → 2.5.0-cx24-2467.3.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-2179.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.1) (2022-11-21)
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)
2
2
 
3
3
 
4
4
  ### Fix
@@ -7,7 +7,7 @@
7
7
 
8
8
  ### New
9
9
 
10
- * added support for variant and promotion (#CX24-2179) ([cf1f623](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/cf1f623c61de55fb969e7debd5c456483f1283b5)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
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)
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-2179.1",
3
+ "version": "2.5.0-cx24-2467.3.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": {
@@ -90,12 +90,13 @@ const ProductData = {
90
90
  },
91
91
 
92
92
  /**
93
- * map product from equinox to nuskin product data structure
93
+ * Map product variant
94
94
  * @todo remove unnecessary fields
95
95
  * @param {*} eqVariant
96
- * @returns obj Product
96
+ * @returns Array<Product>
97
97
  */
98
- productMapper : function(eqVariant) {
98
+ eqProductVariantMapper : function (eqVariant) {
99
+
99
100
  let imageURL = eqVariant.properties.imageURL;
100
101
  const regex = /\d+.\d+/
101
102
  let thumbnailImage = ''
@@ -106,10 +107,7 @@ const ProductData = {
106
107
  thumbnailImage = imageURL.replace(regex,'40.40')
107
108
  }
108
109
 
109
- //get the last promotion
110
- const salesPromotion = Array.isArray(eqVariant.promotion) > 0 ? eqVariant.promotion[eqVariant.promotion.length - 1] : null;
111
- const productPrice = salesPromotion && salesPromotion.discount ? salesPromotion.discount : (eqVariant.priceFacet ? eqVariant.priceFacets["Regular Price"] : '');
112
- return {
110
+ return {
113
111
  "sku": eqVariant.identifier,
114
112
  "globalProductID": eqVariant.identifier,
115
113
  "title": eqVariant.properties.name,
@@ -144,28 +142,28 @@ const ProductData = {
144
142
  "availableQuantity": eqVariant.inventoryProperties.atpQty,
145
143
  "maxQuantity": 999,
146
144
  "points": "",
147
- "cv": eqVariant.priceFacets ? eqVariant.priceFacets.CV : '',
148
- "pv": eqVariant.priceFacets ? eqVariant.priceFacets.PV : '',
145
+ "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
146
+ "pv":eqVariant.priceFacets.PV,
149
147
  "priceType": "WRTL",
150
- "price": productPrice,
148
+ "price": eqVariant.priceFacets["Regular Price"],
151
149
  "priceMap": {
152
- "WRTL": productPrice,
153
- "WADW-WRTL": productPrice,
154
- "WADR": eqVariant.priceFacet ? eqVariant.priceFacets["Regular Price"] : '',
155
- "RTL": eqVariant.priceFacet ? eqVariant.priceFacets["Regular Price"] : '',
156
- "WWHL": eqVariant.priceFacet ? eqVariant.priceFacets["Wholesale Price"] : '',
157
- "WADW": eqVariant.priceFacet ? eqVariant.priceFacets["Wholesale Price"] : '',
158
- "WHL": eqVariant.priceFacet ? eqVariant.priceFacets["Wholesale Price"] : ''
150
+ "WRTL": eqVariant.priceFacets["Regular Price"],
151
+ "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
152
+ "WADR": eqVariant.priceFacets["Regular Price"],
153
+ "RTL": eqVariant.priceFacets["Regular Price"],
154
+ "WWHL": eqVariant.priceFacets["Wholesale Price"],
155
+ "WADW": eqVariant.priceFacets["Wholesale Price"],
156
+ "WHL": eqVariant.priceFacets["Wholesale Price"]
159
157
  },
160
158
  "cvMap": {
161
- "WWHL": (eqVariant.priceFacets) ? eqVariant.priceFacets.CV : '',
162
- "WADW": (eqVariant.priceFacets) ? eqVariant.priceFacets.CV : '',
163
- "WHL": (eqVariant.priceFacets) ? eqVariant.priceFacets.CV : ''
159
+ "WWHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
160
+ "WADW": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
161
+ "WHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : ''
164
162
  },
165
163
  "pvMap": {
166
- "WWHL": eqVariant.priceFacets ? eqVariant.priceFacets.PV : '',
167
- "WADW": eqVariant.priceFacets ? eqVariant.priceFacets.PV : '',
168
- "WHL": eqVariant.priceFacets ? eqVariant.priceFacets.PV : ''
164
+ "WWHL": eqVariant.priceFacets.PV,
165
+ "WADW": eqVariant.priceFacets.PV,
166
+ "WHL": eqVariant.priceFacets.PV
169
167
  },
170
168
  "orderTypes": this._setOrderType(eqVariant.properties),
171
169
  "division": eqVariant.properties.division,
@@ -183,9 +181,9 @@ const ProductData = {
183
181
  "variantsLabel": eqVariant.properties.variantLabel || "",
184
182
  "groupOffer": false,
185
183
  "personalOffer": false,
186
- "savedEventName": salesPromotion ? salesPromotion.promotionClass : '',
187
- "salesLabel": salesPromotion ? salesPromotion.message : '',
188
- "eventName": salesPromotion ? salesPromotion.promotionClass : '',
184
+ "savedEventName": null,
185
+ "salesLabel": "",
186
+ "eventName": null,
189
187
  "sizeWeight": '',
190
188
  "nettoWeight": "",
191
189
  "searchScore": 0,
@@ -198,57 +196,134 @@ const ProductData = {
198
196
  "restrictedMarkets": [],
199
197
  "addOns": []
200
198
  };
201
-
202
- },
203
-
204
-
205
- /**
206
- *
207
- * Map product variants
208
- * @param Array<eqVariant>
209
- * @returns Array<Product>
210
- */
211
- eqProductVariantMapper : function (eqVariants) {
212
-
213
- let variants = {};
214
-
215
- eqVariants.map(eqVariant => {
216
- variants[eqVariant.identifier] = this.productMapper(eqVariant);
217
- return eqVariant;
218
- });
219
-
220
- return variants;
221
199
  },
222
200
 
223
-
224
- /**
225
- * eqProductMapper
226
- * @param {*} productDataResponse
227
- * @param {*} skus
228
- * @returns obj
229
- */
230
201
  eqProductMapper: function (productDataResponse, skus) {
202
+ let prod = [];
231
203
  let count = 0;
232
204
  let variants = {};
233
205
 
234
206
  let prodArr = productDataResponse.map((data) => {
235
-
236
- const mappedProduct = this.productMapper(data.sku[count]);
237
-
238
- if (data.sku && data.sku.length > 0) {
239
- variants = this.eqProductVariantMapper(data.sku);
207
+ let imageURL = data.sku[count].properties.imageURL;
208
+ const regex = /\d+.\d+/
209
+ let thumbnailImage = ''
210
+
211
+ if (imageURL.includes('contentstack')) {
212
+ thumbnailImage = imageURL + '?width=40'
213
+ } else {
214
+ thumbnailImage = imageURL.replace(regex,'40.40')
240
215
  }
241
216
 
242
- let newProduct = new Product({...mappedProduct, variants: variants});
243
- return newProduct;
217
+ 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
+ });
223
+ }
244
224
 
245
- });
225
+ prod = {
226
+ "sku": data.sku[count].identifier,
227
+ "globalProductID": data.identifier,
228
+ "title": data.properties.name,
229
+ "country": data.sku[count].properties.market,
230
+ "language": "en",
231
+ "shortDescr": data.properties.description,
232
+ "longDescr": data.properties.productDetailsDescription,
233
+ "fullImage": imageURL,
234
+ "imageAltText": data.properties.name,
235
+ "productCarouselImages": [
236
+ {
237
+ "contentType": "img",
238
+ "src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
239
+ "alt": ""
240
+ }
241
+ ],
242
+ "thumbnail": thumbnailImage,
243
+ "ingredients": data.properties.ingredients,
244
+ "benefits": data.properties.benefits,
245
+ "usage": data.properties.usage,
246
+ "resources": data.sku[count].properties.resources,
247
+ "videos": "",
248
+ "movie": "",
249
+ "youtube": "",
250
+ "salesEventText": "",
251
+ "contentSection": [
252
+ {
253
+ "sectionContent": "<div class=\"contentSections\"></div>\n"
254
+ }
255
+ ],
256
+ "scanQualified": data.properties.scanQualifiedCount,
257
+ "availableQuantity": data.sku[count].inventoryProperties.atpQty,
258
+ "maxQuantity": 999,
259
+ "points": "",
260
+ "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
261
+ "pv": data.sku[count].priceFacets.PV,
262
+ "priceType": "WRTL",
263
+ "price": data.sku[count].priceFacets["Regular Price"],
264
+ "priceMap": {
265
+ "WRTL": data.sku[count].priceFacets["Regular Price"],
266
+ "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
267
+ "WADR": data.sku[count].priceFacets["Regular Price"],
268
+ "RTL": data.sku[count].priceFacets["Regular Price"],
269
+ "WADW": data.sku[count].priceFacets["Wholesale Price"],
270
+ "WHL": data.sku[count].priceFacets["Wholesale Price"],
271
+ "WWHL": data.sku[count].priceFacets["Wholesale Price"]
272
+ },
273
+ "cvMap": {
274
+ "WWHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
275
+ "WADW": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
276
+ "WHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : ''
277
+ },
278
+ "pvMap": {
279
+ "WWHL": data.sku[count].priceFacets.PV,
280
+ "WADW": data.sku[count].priceFacets.PV,
281
+ "WHL": data.sku[count].priceFacets.PV
282
+ },
283
+ "orderTypes": this._setOrderType(data.sku[count].properties),
284
+ "childSkus": [],
285
+ "custTypes": this.switchCustType(data.properties.customerTypes),
286
+ "division": data.properties.division,
287
+ "backOrderDate": null,
288
+ "locallyProduced": false,
289
+ "agelocme": null,
290
+ "count": "",
291
+ "flavor": "",
292
+ "size": data.sku[count].properties.size,
293
+ "shade": "",
294
+ "status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
295
+ "variantType": "Other",
296
+ "variantDropdownLabel": data.sku[count].properties.variantLabel || "",
297
+ "variantDropdownPlaceholder": "Select Type",
298
+ "variantsLabel": data.sku[count].properties.variantLabel || "",
299
+ "groupOffer": false,
300
+ "personalOffer": false,
301
+ "savedEventName": null,
302
+ "salesLabel": "",
303
+ "eventName": null,
304
+ "sizeWeight": '',
305
+ "nettoWeight": "",
306
+ "variants": variants,
307
+ "searchScore": 0,
308
+ "isExclusive": data.sku[count].properties.isExclusive,
309
+ "marketAttributes": {
310
+ "discount": true,
311
+ "redeem": true,
312
+ "earn": true
313
+ },
314
+ "restrictedMarkets": [],
315
+ "addOns": [],
316
+ "inventory": data.sku[count].inventory || "" //inventory label
317
+
318
+ };
319
+ let newProduct = new Product(prod);
320
+ return newProduct
321
+ })
246
322
 
247
323
  let data = {
248
324
  products: this._sortProductsBySku(skus, prodArr),
249
325
  count: productDataResponse.length
250
326
  };
251
-
252
327
  return {
253
328
  data: {
254
329
  "status": 200,