@nuskin/ns-product-lib 2.13.0-cx24-5107.13 → 2.13.0-cx24-5107.15

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ # [2.13.0-cx24-5107.15](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.13.0-cx24-5107.14...v2.13.0-cx24-5107.15) (2023-10-19)
2
+
3
+
4
+ ### Fix
5
+
6
+ * productImages null causing exception ([ad59208](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ad59208a71d3af8104b7c84a4b32142d343f4918))
7
+
8
+ ### Updae
9
+
10
+ * added price unit testng ([3857a3f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3857a3f6effe0707cb328abe1cdd33d7953b6dfa))
11
+
12
+ # [2.13.0-cx24-5107.14](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.13.0-cx24-5107.13...v2.13.0-cx24-5107.14) (2023-10-19)
13
+
14
+
15
+ ### New
16
+
17
+ * Handle adding variants from bundle ([bce1628](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bce1628f5e6b1bec99d37da1481a3e53fe7f7a1e))
18
+
1
19
  # [2.13.0-cx24-5107.13](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.13.0-cx24-5107.12...v2.13.0-cx24-5107.13) (2023-10-16)
2
20
 
3
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.13.0-cx24-5107.13",
3
+ "version": "2.13.0-cx24-5107.15",
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": {
@@ -7,9 +7,27 @@ const mapBackOrderDate = require('./backOrderDate');
7
7
  * @param {import('.').EquinoxNormalProduct} product
8
8
  */
9
9
  function childSKUBundle(kits, product) {
10
- const sku = product.sku.filter(sku => sku.default)[0];
10
+ let sku;
11
+ let personalOffer = JSON.parse(sessionStorage.getItem('personalOffer'))
12
+ if (personalOffer.active) {
13
+ //get the products with variants selected
14
+ const productWithVariant = personalOffer.products.filter((sku) => sku.variantSelected !== null)[0]
15
+ if (productWithVariant !== null) {
16
+ sku = product.sku.filter((sku) => {
17
+ console.log('Checking sku ' + sku.identifier + ` ` + product.identifier)
18
+ return sku.identifier === productWithVariant.variantSelected[product.identifier]
19
+ })[0]
20
+ }
21
+ if (!sku) {
22
+ sku = product.sku.filter(sku => sku.default)[0];
23
+ }
24
+ } else {
25
+ sku = product.sku.filter(sku => sku.default)[0];
26
+ }
27
+
28
+
11
29
  if (!sku) {
12
- throw Error('Unable to find the default SKU.');
30
+ throw Error('Unable to find the default SKU for product ' + product.identifier);
13
31
  }
14
32
 
15
33
  const kit = kits.filter(k => k.sku === product.identifier)[0];
@@ -31,4 +49,5 @@ function childSKUBundle(kits, product) {
31
49
  }
32
50
  }
33
51
 
52
+
34
53
  module.exports = childSKUBundle;
@@ -14,10 +14,9 @@ const defaultPayload = {
14
14
  * @param {obj} payload
15
15
  * @returns {Promise}
16
16
  */
17
- async function graphQlHttpRequest(payload, config) {
18
- //const url = getGraphQlUrl();
17
+ function graphQlHttpRequest(payload, config) {
19
18
  const url = config.graphqlUrl
20
- return await axios.request({
19
+ return axios.request({
21
20
  method: 'post',
22
21
  url: url,
23
22
  data: payload,
@@ -99,6 +98,7 @@ function mapProduct(product, market, locale, config) {
99
98
 
100
99
  //serves as parent
101
100
  const defaultVariant = variants[0];
101
+ const productImages = mapProductImages(defaultVariant);
102
102
  const productDetail = {
103
103
  "sku": defaultVariant.sku || product.id,
104
104
  "globalProductID": product.id,
@@ -107,9 +107,9 @@ function mapProduct(product, market, locale, config) {
107
107
  "language": locale,
108
108
  "shortDescr": defaultVariant.description,
109
109
  "longDescr": defaultVariant.productDetails.description,
110
- "fullImage": defaultVariant.productImages[0].url,
111
- "imageAltText": defaultVariant.productImages[0].alt,
112
- "thumbnail": defaultVariant.productImages[0].thumbnail,
110
+ "fullImage": productImages.fullImage,
111
+ "imageAltText": productImages.imageAltText,
112
+ "thumbnail": productImages.thumbnail,
113
113
  "ingredients": defaultVariant.ingredients,
114
114
  "benefits": defaultVariant.benefits,
115
115
  "usage": defaultVariant.usage,
@@ -208,15 +208,18 @@ function mapVariants(product) {
208
208
 
209
209
  product.variants.forEach(variant => {
210
210
  const sku = variant.sku || variant.id;
211
+
212
+ const productImages = mapProductImages(variant);
213
+
211
214
  variants[sku] = {
212
215
  "sku": sku,
213
216
  "globalProductID": product.id || variant.globalId,
214
217
  "title": variant.title,
215
218
  "shortDescr": variant.description,
216
219
  "longDescr": variant.productDetails.description,
217
- "fullImage": variant.productImages[0].url,
218
- "imageAltText": variant.productImages[0].alt,
219
- "thumbnail": variant.productImages[0].thumbnail,
220
+ "fullImage": productImages.fullImage,
221
+ "imageAltText": productImages.imageAltText,
222
+ "thumbnail": productImages.thumbnail,
220
223
  "ingredients": variant.ingredients,
221
224
  "benefits": variant.benefits,
222
225
  "usage": variant.usage,
@@ -335,6 +338,32 @@ function mapCustomerTypes(eqCustomerTypes) {
335
338
  return newCustType.toString()
336
339
  }
337
340
 
341
+ /**
342
+ * map product Images
343
+ * {
344
+ * url: "string",
345
+ * alt: "string",
346
+ * thumbnail: "string"
347
+ * }
348
+ * @param {*} product
349
+ * @returns {object} productImages
350
+ */
351
+ function mapProductImages(product) {
352
+
353
+ const productImages = {
354
+ fullImage: "",
355
+ imageAltText: "",
356
+ thumbnail: ""
357
+ };
358
+
359
+ if (product.productImages) {
360
+ productImages.fullImage = product.productImages.url || '';
361
+ productImages.imageAltText = product.productImages.alt || '';
362
+ productImages.thumbnail = product.productImages.thumbnail || '';
363
+ }
364
+
365
+ return productImages;
366
+ }
338
367
  /**
339
368
  * Map Order Types
340
369
  * @param {Array<string>} availableChannels