@nuskin/ns-product-lib 2.13.3-cx24-5694.1 → 2.13.3-cx24-5694.3

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.13.3-cx24-5694.1",
3
+ "version": "2.13.3-cx24-5694.3",
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": {
@@ -3,11 +3,12 @@ const wholesalePrice = require('./wholesalePrice');
3
3
  const retailPrice = require('./retailPrice');
4
4
  const retailSubscriptionPrice = require('./retailSubscriptionPrice')
5
5
  const wholesaleSubscriptionPrice = require('./wholesaleSubscriptionPrice')
6
-
6
+ const originalPrice = require('./originalPrice');
7
7
 
8
8
  module.exports = {
9
9
  mapWholesalePrice: wholesalePrice,
10
10
  mapRetailPrice: retailPrice,
11
11
  mapRetailSubscriptionPrice: retailSubscriptionPrice,
12
- mapWholesaleSubscriptionPrice: wholesaleSubscriptionPrice
12
+ mapWholesaleSubscriptionPrice: wholesaleSubscriptionPrice,
13
+ mapOriginalPrice : originalPrice
13
14
  }
@@ -0,0 +1,24 @@
1
+
2
+
3
+ /**
4
+ * Map original price (set to retail)
5
+ * use original price if product type is equal to kit/bundle
6
+ * @param {obj} product
7
+ * @param {boolean} isWholesale default === false
8
+ * @param {boolean} isBundleKit default === false
9
+ * @return {number} retailPrice
10
+ */
11
+ function originalPrice(product, isWholesale = false, isBundleKit = false) {
12
+ const { price, totalPrice } = product;
13
+ const productPrice = price ? price : totalPrice;
14
+
15
+ if (isBundleKit) {
16
+
17
+ return isWholesale ? productPrice.wholesaleOriginal : productPrice.retailOriginal;
18
+ }
19
+
20
+ return isWholesale ? productPrice.wholesale : productPrice.retail;
21
+
22
+ }
23
+
24
+ module.exports = originalPrice;
@@ -8,14 +8,14 @@
8
8
  */
9
9
  function retailPrice(product) {
10
10
  const { price, totalPrice } = product;
11
- const productPrice = totalPrice ? totalPrice : price;
11
+ const productPrice = price ? price : totalPrice;
12
12
 
13
13
  if (productPrice.retailSales) {
14
14
 
15
15
  return productPrice.retailSales;
16
16
  }
17
17
 
18
- return productPrice.retail;
18
+ return productPrice.retail;
19
19
 
20
20
  }
21
21
 
@@ -8,7 +8,7 @@
8
8
  */
9
9
  function retailSubscriptionPrice(product) {
10
10
  const { price, totalPrice } = product;
11
- const productPrice = totalPrice ? totalPrice : price;
11
+ const productPrice = price ? price : totalPrice;
12
12
 
13
13
  if (productPrice.retailSales) {
14
14
 
@@ -8,7 +8,7 @@
8
8
  */
9
9
  function wholeSalePrice(product) {
10
10
  const { price, totalPrice } = product;
11
- const productPrice = totalPrice ? totalPrice : price;
11
+ const productPrice = price ? price : totalPrice;
12
12
 
13
13
  if (productPrice.wholesaleSales) {
14
14
  return productPrice.wholesaleSales;
@@ -8,7 +8,7 @@
8
8
  */
9
9
  function wholesaleSubscriptionPrice(product) {
10
10
  const { price, totalPrice } = product;
11
- const productPrice = totalPrice ? totalPrice : price;
11
+ const productPrice = price ? price : totalPrice;
12
12
 
13
13
  if (productPrice.wholesaleSales) {
14
14
 
@@ -7,7 +7,9 @@ const {
7
7
  mapWholesalePrice,
8
8
  mapRetailPrice,
9
9
  mapRetailSubscriptionPrice,
10
- mapWholesaleSubscriptionPrice } = require('./mappers');
10
+ mapWholesaleSubscriptionPrice,
11
+ mapOriginalPrice
12
+ } = require('./mappers');
11
13
 
12
14
  const defaultPayload = {
13
15
  operationName: "getProduct",
@@ -77,6 +79,32 @@ async function getProduct(id, market, locale, config) {
77
79
  };
78
80
  }
79
81
 
82
+ /**
83
+ * Map product prices
84
+ * @param {*} product
85
+ * @param {boolean} isKitBundle
86
+ * @return {obj} prices
87
+ */
88
+ function mapPrices(product, isKitBundle = false) {
89
+ const originalPrice = mapOriginalPrice(product, false, isKitBundle) || 0;
90
+ const retailPrice = mapRetailPrice(product) || 0;
91
+ const wholesalePrice = mapWholesalePrice(product) || 0;
92
+ const originalWholeSalePrice = mapOriginalPrice(product, true, isKitBundle) || 0;
93
+
94
+ //map subscription (ADR) prices
95
+ const retailSubscriptionPrice = mapRetailSubscriptionPrice(product) || 0;
96
+ const wholesaleSubscriptionPrice = mapWholesaleSubscriptionPrice(product) || 0;
97
+
98
+ return {
99
+ originalPrice,
100
+ originalWholeSalePrice,
101
+ retailPrice,
102
+ wholesalePrice,
103
+ retailSubscriptionPrice,
104
+ wholesaleSubscriptionPrice
105
+ }
106
+ }
107
+
80
108
  /**
81
109
  *
82
110
  * Map product data to be product card consumable structure *
@@ -108,6 +136,16 @@ function mapProduct(product, market, locale, config) {
108
136
  //serves as parent
109
137
  const defaultVariant = variants[0];
110
138
  const productImages = mapProductImages(defaultVariant);
139
+
140
+ const {
141
+ originalPrice,
142
+ retailPrice,
143
+ wholesalePrice,
144
+ retailSubscriptionPrice,
145
+ wholesaleSubscriptionPrice,
146
+ originalWholeSalePrice
147
+ } = mapPrices(defaultVariant, !!kitBundleProducts);
148
+
111
149
  const productDetail = {
112
150
  "sku": defaultVariant.sku || product.id,
113
151
  "globalProductID": product.id,
@@ -129,15 +167,15 @@ function mapProduct(product, market, locale, config) {
129
167
  "cv": (defaultVariant.points) ? defaultVariant.points.wholesale.cv : 0,
130
168
  "pv": (defaultVariant.points) ? defaultVariant.points.wholesale.pv : 0,
131
169
  "priceType": "WRTL",
132
- "price": mapRetailPrice(defaultVariant),
170
+ "price": originalPrice,
133
171
  "priceMap": {
134
- "WRTL": mapRetailPrice(defaultVariant),
135
- "WADW-WRTL": mapRetailSubscriptionPrice(defaultVariant),
136
- "WADR": mapRetailSubscriptionPrice(defaultVariant), //retail ADR (subscription) price
137
- "RTL": mapRetailPrice(defaultVariant),
138
- "WWHL": mapWholesalePrice(defaultVariant),
139
- "WADW": mapWholesaleSubscriptionPrice(defaultVariant),//wholesale ADR (subscription price)
140
- "WHL": mapWholesalePrice(defaultVariant)
172
+ "WRTL": retailPrice,
173
+ "WADW-WRTL": retailSubscriptionPrice,
174
+ "WADR": retailSubscriptionPrice,
175
+ "RTL": retailPrice,
176
+ "WWHL": wholesalePrice,
177
+ "WADW": wholesaleSubscriptionPrice,
178
+ "WHL": originalWholeSalePrice
141
179
  },
142
180
  "cvMap": {
143
181
  "WWHL": (defaultVariant.points) ? defaultVariant.points.wholesale.cv : 0,
@@ -219,6 +257,13 @@ function mapVariants(product) {
219
257
  const sku = variant.sku || variant.id;
220
258
 
221
259
  const productImages = mapProductImages(variant);
260
+ const {
261
+ originalPrice,
262
+ retailPrice,
263
+ wholesalePrice,
264
+ retailSubscriptionPrice,
265
+ wholesaleSubscriptionPrice
266
+ } = mapPrices(variant);
222
267
 
223
268
  variants[sku] = {
224
269
  "sku": sku,
@@ -239,15 +284,15 @@ function mapVariants(product) {
239
284
  "cv": (variant.points) ? variant.points.wholesale.cv : 0,
240
285
  "pv": (variant.points) ? variant.points.wholesale.pv : 0,
241
286
  "priceType": "WRTL",
242
- "price": mapRetailPrice(variant),
287
+ "price": originalPrice,
243
288
  "priceMap": {
244
- "WRTL": mapRetailPrice(variant),
245
- "WADW-WRTL": mapRetailSubscriptionPrice(variant),
246
- "WADR": mapRetailSubscriptionPrice(variant), //retail ADR (subscription) price
247
- "RTL": mapRetailPrice(variant),
248
- "WWHL": mapWholesalePrice(variant),
249
- "WADW": mapWholesaleSubscriptionPrice(variant),//wholesale ADR (subscription price)
250
- "WHL": mapWholesalePrice(variant)
289
+ "WRTL": retailPrice,
290
+ "WADW-WRTL": retailSubscriptionPrice,
291
+ "WADR": retailSubscriptionPrice,
292
+ "RTL": retailPrice,
293
+ "WWHL": wholesalePrice,
294
+ "WADW": wholesaleSubscriptionPrice,
295
+ "WHL": wholesalePrice
251
296
  },
252
297
  "cvMap": {
253
298
  "WWHL": (variant.points) ? variant.points.wholesale.cv : 0,
@@ -360,6 +360,8 @@ const getProductByIdQuery = `query getProduct($id: String!, $market: String, $la
360
360
  wholesaleSales
361
361
  retailSubscription
362
362
  wholesaleSubscription
363
+ retailOriginal
364
+ wholesaleOriginal
363
365
  currencyCode
364
366
  __typename
365
367
  }
@@ -370,6 +372,8 @@ const getProductByIdQuery = `query getProduct($id: String!, $market: String, $la
370
372
  wholesaleSales
371
373
  retailSubscription
372
374
  wholesaleSubscription
375
+ retailOriginal
376
+ wholesaleOriginal
373
377
  currencyCode
374
378
  __typename
375
379
  }
@@ -448,6 +452,8 @@ const getProductByIdQuery = `query getProduct($id: String!, $market: String, $la
448
452
  wholesaleSales
449
453
  retailSubscription
450
454
  wholesaleSubscription
455
+ retailOriginal
456
+ wholesaleOriginal
451
457
  __typename
452
458
  }
453
459
  totalPrice {
@@ -458,6 +464,8 @@ const getProductByIdQuery = `query getProduct($id: String!, $market: String, $la
458
464
  wholesaleSales
459
465
  retailSubscription
460
466
  wholesaleSubscription
467
+ retailOriginal
468
+ wholesaleOriginal
461
469
  __typename
462
470
  }
463
471
  points {
@@ -362,6 +362,8 @@ const getProductsByIdQuery = `query getProducts($id: String!, $market: String, $
362
362
  retailSubscription
363
363
  wholesaleSubscription
364
364
  currencyCode
365
+ retailOriginal
366
+ wholesaleOriginal
365
367
  __typename
366
368
  }
367
369
  totalPrice {
@@ -372,6 +374,8 @@ const getProductsByIdQuery = `query getProducts($id: String!, $market: String, $
372
374
  retailSubscription
373
375
  wholesaleSubscription
374
376
  currencyCode
377
+ retailOriginal
378
+ wholesaleOriginal
375
379
  __typename
376
380
  }
377
381
  points {
@@ -449,6 +453,8 @@ const getProductsByIdQuery = `query getProducts($id: String!, $market: String, $
449
453
  wholesaleSales
450
454
  retailSubscription
451
455
  wholesaleSubscription
456
+ retailOriginal
457
+ wholesaleOriginal
452
458
  __typename
453
459
  }
454
460
  totalPrice {
@@ -459,6 +465,8 @@ const getProductsByIdQuery = `query getProducts($id: String!, $market: String, $
459
465
  wholesaleSales
460
466
  retailSubscription
461
467
  wholesaleSubscription
468
+ retailOriginal
469
+ wholesaleOriginal
462
470
  __typename
463
471
  }
464
472
  points {
@@ -1,5 +1,5 @@
1
1
  const getProductByIdQuery = require('./getProductById');
2
2
 
3
3
  module.exports = {
4
- getProductById: getProductByIdQuery
4
+ getProductByIdQuery
5
5
  }