@nuskin/ns-shop 7.0.11-pur-813.1 → 7.0.11-pur-813.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-shop",
3
- "version": "7.0.11-pur-813.1",
3
+ "version": "7.0.11-pur-813.3",
4
4
  "description": "The description that will amaze and astound your audience when they read it",
5
5
  "main": "src/shop.js",
6
6
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  "@nuskin/ns-common-lib": "1.4.7",
27
27
  "@nuskin/ns-feature-flags": "1.4.7",
28
28
  "@nuskin/ns-loyalty-web": "1.5.6",
29
- "@nuskin/ns-product-lib": "2.17.6",
29
+ "@nuskin/ns-product-lib": "2.19.1",
30
30
  "@nuskin/nuskinjquery": "2.3.1",
31
31
  "@nuskin/order-model": "3.1.3",
32
32
  "@nuskin/product-lib": "2.2.1",
@@ -34,6 +34,7 @@ export default {
34
34
  hasItems,
35
35
  hasEventItems,
36
36
  hasPreviewItems,
37
+ hasDanerousGoods,
37
38
  getItemCnt,
38
39
  addProductToCart,
39
40
  addSkuToCart,
@@ -298,6 +299,14 @@ function hasPreviewItems() {
298
299
  return _getCart().hasPreviewItems();
299
300
  }
300
301
 
302
+ function hasDanerousGoods(options = {cartOrderItems: true}) {
303
+ let retVal = false;
304
+ _getCart().getItems(options).forEach((item) => {
305
+ retVal = retVal || item.product.dangerousGoods;
306
+ });
307
+ return retVal;
308
+ }
309
+
301
310
  function getItemCnt(options) {
302
311
  return _getCart().getItemCnt(options);
303
312
  }
@@ -0,0 +1,267 @@
1
+ import {productLib} from '@nuskin/product-lib';
2
+ import {RunConfigService, events, UrlService, BrowserDetection} from '@nuskin/ns-util';
3
+ import { getConfiguration } from '@nuskin/configuration-sdk';
4
+ import {AccountManager} from '@nuskin/ns-account';
5
+ import {PriceType, Product} from '@nuskin/ns-product-lib';
6
+
7
+ const extractProductData = (data, sku) => {
8
+ let retVal;
9
+
10
+ if (Array.isArray(data.variants) && data.variants.length > 0) {
11
+ retVal = data.variants.find((variant) => variant.sku === sku);
12
+ retVal.variantSelectLabel = data.variantSelectLabel;
13
+ } else if (data.bundle) {
14
+ retVal = data.bundle;
15
+ retVal.title = data.title;
16
+ retVal.productImages = data.productImages;
17
+ }
18
+
19
+ return retVal;
20
+ }
21
+
22
+ const addPrice = (productData, priceTypeKey, subKey, priceValue) => {
23
+ if (!['Points', 'cv', 'price', 'pv'].includes(priceTypeKey)) {
24
+ // if the priceTypeKey is not one of these, then we don't want it to show.
25
+ return;
26
+ }
27
+ if (priceTypeKey === 'pv') {
28
+ priceTypeKey = 'psv';
29
+ }
30
+ if (priceTypeKey === 'cv') {
31
+ priceTypeKey = 'csv';
32
+ }
33
+
34
+ if (productData[priceTypeKey] === undefined) {
35
+ if (priceTypeKey === 'Points') {
36
+ if (!productData.price) {
37
+ productData.price = {};
38
+ }
39
+ productData.price.PTS = priceValue;
40
+ return;
41
+ } else {
42
+ productData[priceTypeKey] = {};
43
+ }
44
+ }
45
+ productData[priceTypeKey][subKey] = priceValue;
46
+ }
47
+
48
+ const convertPricing = (pricing, productData) => {
49
+ if (pricing) {
50
+ Object.keys(pricing).forEach((channelKey) => {
51
+ Object.keys(pricing[channelKey]).forEach((contextKey) => {
52
+ Object.keys(pricing[channelKey][contextKey]).forEach((priceTypeKey) => {
53
+ const priceValue = pricing[channelKey][contextKey][priceTypeKey];
54
+ switch (channelKey) {
55
+ case 'wholesale':
56
+ switch (contextKey) {
57
+ case 'webOrder':
58
+ addPrice(productData, priceTypeKey, 'WWHL', priceValue);
59
+ break;
60
+ case 'webAdr':
61
+ case 'WADW':
62
+ case 'ADR5':
63
+ addPrice(productData, priceTypeKey, 'WADW', priceValue);
64
+ break;
65
+ case 'order':
66
+ case 'WHL':
67
+ addPrice(productData, priceTypeKey, 'WHL', priceValue);
68
+ break;
69
+ case 'adr':
70
+ addPrice(productData, priceTypeKey, 'ADW', priceValue);
71
+ break;
72
+ case 'ADR10':
73
+ case 'WADWD':
74
+ addPrice(productData, priceTypeKey, 'WADWD', priceValue);
75
+ break;
76
+ default:
77
+ addPrice(
78
+ productData,
79
+ priceTypeKey,
80
+ `${contextKey}-WWHL`,
81
+ priceValue
82
+ );
83
+ break;
84
+ }
85
+ break;
86
+ case 'retail':
87
+ switch (contextKey) {
88
+ case 'webOrder':
89
+ addPrice(productData, priceTypeKey, 'WRTL', priceValue);
90
+ break;
91
+ case 'webAdr':
92
+ addPrice(productData, priceTypeKey, 'WADR', priceValue);
93
+ break;
94
+ case 'order':
95
+ case 'RTL':
96
+ addPrice(productData, priceTypeKey, 'RTL', priceValue);
97
+ break;
98
+ case 'adr':
99
+ addPrice(productData, priceTypeKey, 'ADR', priceValue);
100
+ break;
101
+ default:
102
+ addPrice(
103
+ productData,
104
+ priceTypeKey,
105
+ `${contextKey}-WRTL`,
106
+ priceValue
107
+ );
108
+ break;
109
+ }
110
+ break;
111
+ }
112
+ });
113
+ });
114
+ });
115
+ }
116
+ }
117
+
118
+ const createDataFromSkuSearch = (searchData, options) => {
119
+ if (!searchData) {
120
+ return new Product();
121
+ }
122
+ let product = new Product();
123
+
124
+ if (searchData) {
125
+ product.sku = options.sku;
126
+ product.country = options.country;
127
+ product.lang = options.language;
128
+ product.isExclusive = searchData.isExclusive;
129
+ if (Array.isArray(searchData.productImages) && searchData.productImages.length > 0) {
130
+ product.setFullImage(searchData.productImages[0].url);
131
+ product.setThumbnail(searchData.productImages[0].thumbnail);
132
+ product.setImageAltText(searchData.productImages[0].altText);
133
+ // product.setProductCarouselImages(???searchData.contents.imageCarousel);
134
+ }
135
+ // product.productLabels = ???
136
+ product.title = searchData.title;
137
+ product.shortDescr = searchData.description;
138
+ // product.longDescr = langObj['longDescription']; looks like it is deprecated
139
+ product.dangerousGoods = searchData.dangerousGoods === true;
140
+ product.ingredients = searchData.ingredients;
141
+ product.benefits = searchData.benefits;
142
+ product.usage = searchData.usage;
143
+ product.resources = searchData.resources;
144
+ // product.videos = searchData.???;
145
+ // product.contentSection =searchData.???;
146
+ // product.sizeWeight = ???;
147
+ product.size = searchData.size;
148
+ product.nettoWeight = searchData.nettoWeight;
149
+ product.salesLabel = searchData.salesLabel;
150
+ // product.movie = searchData.???;
151
+ // product.youtube = searchData.???;
152
+ product.salesEventText = searchData.salesText;
153
+ product.scanQualified = searchData.scanQualifiedCount;
154
+ // product.division = searchData.???
155
+ product.custTypes = Array.isArray(searchData.customerTypes) && searchData.customerTypes.map((ct) => {
156
+ if (ct === 'Preferred') return '30';
157
+ else if (ct === 'Retail') return '20';
158
+ else if (ct === '') return '10';
159
+ });
160
+ product.restrictedMarkets = searchData.restrictedMarkets;
161
+ // if (addOns) {
162
+ // product.addOns = addOns;
163
+ // } else {
164
+ // product.addOns = [];
165
+ // }
166
+ if (options.isGroupOffer) product.isGroupOffer = options.isGroupOffer;
167
+ if (options.isPersonalOffer) product.isPersonalOffer = options.isPersonalOffer;
168
+
169
+ product.variantsLabel = searchData.variantLabel;
170
+ product.variantDropdownLabel = searchData.variantSelectLabel;
171
+ product.shade = searchData.variantColor;
172
+
173
+ const pricing = JSON.parse(searchData.pricingJson);
174
+ const orderTypes = [];
175
+ if (searchData.purchaseTypes.buyOnce) orderTypes.push('order');
176
+ if (searchData.purchaseTypes.subscription) orderTypes.push('adr');
177
+ let status = {
178
+ sku: options.sku,
179
+ globalProductId: searchData.globalId,
180
+ status: searchData.status.status === 'sellable' ? 'RELEASED_FOR_SALE' : 'NOT_RELEASED_FOR_SALE',
181
+ availableQuantity: searchData.availableQuantity,
182
+ maxQuantity: searchData.maxQuantity,
183
+ locallyProduced: searchData.locallyProduced, // ???
184
+ backorderedAvailableDate: searchData.status.isBackordered > 0 ? searchData.status.backorderedAvailableDate : null,
185
+ orderType: orderTypes, // searchData.channels.map((channel) => channel.toLowerCase()),
186
+ childSkus: null // ???
187
+ };
188
+ convertPricing(pricing, status);
189
+ product.addPricingFromStatus(status);
190
+ }
191
+
192
+ // Note: this mapping was originally created for the product data in AEM. This product
193
+ // data comes from content stack and is not identical to what is in AEM. There may
194
+ // need to be some tweaks in here. ESPECIALLY when the data gets moved to the
195
+ // bundle field (vs variants) in the product data.
196
+
197
+ return product;
198
+ }
199
+
200
+ const handleDetailResponse = async (responseData, options) => {
201
+ let retVal = {success: true},
202
+ dataForProduct = createDataFromSkuSearch(responseData, options);
203
+
204
+ if (dataForProduct.sku) {
205
+ retVal.product = new Product(dataForProduct);
206
+
207
+ const siteUrl = UrlService.getSiteUrl();
208
+ const isEdge = BrowserDetection.isEdge();
209
+ const isFirefox = BrowserDetection.isFirefox();
210
+
211
+ // set the base url for images, etc
212
+ retVal.product.setBaseUrl(siteUrl);
213
+
214
+ // fix image paths for non-edge/firefox
215
+ if (!isEdge && !isFirefox) {
216
+ retVal.product.fullImage = retVal.product.fullImage
217
+ ? `${retVal.product.fullImage.split("?")[0]}?format=pjpg`
218
+ : undefined;
219
+ retVal.product.thumbnail = retVal.product.thumbnail
220
+ ? `${retVal.product.thumbnail.split("?")[0]}?format=pjpg`
221
+ : undefined;
222
+ }
223
+ } else {
224
+ retVal.success = false;
225
+ retVal.failedSku = options.sku;
226
+ }
227
+
228
+ if (retVal.product && options.priceType) {
229
+ const {Cart: cartCfg} = await getConfiguration(['Cart']);
230
+ const priceType = cartCfg.showWholeSalePricing && !AccountManager.isLoggedIn()
231
+ ? PriceType.WWHL
232
+ : options.priceType;
233
+ retVal.product.setPriceAndPvFromType(priceType);
234
+ }
235
+
236
+ return retVal;
237
+ }
238
+
239
+ const getProductDetail = async (options) => {
240
+ let response;
241
+
242
+ // Hit the PMD and get all the data for the product including the price information.
243
+ try {
244
+ response = await productLib.getProduct({
245
+ fromId: options.sku,
246
+ env: RunConfigService.getEnvironmentCode(),
247
+ market: options.country,
248
+ language: options.language
249
+ })
250
+ } catch (e) {
251
+ throw {error: e, failedSku: options.sku, type: events.errors.PRODUCT_LOOKUP};
252
+ }
253
+
254
+ return extractProductData(response.data, options.sku);
255
+ }
256
+
257
+ const getProductBySku = async (options) => {
258
+ const data = await getProductDetail(options);
259
+
260
+ let result = await handleDetailResponse(data, options);
261
+
262
+ return result;
263
+ }
264
+
265
+ export {
266
+ getProductBySku
267
+ }
@@ -1,11 +1,12 @@
1
1
  import $ from '@nuskin/nuskinjquery';
2
2
  import {PriceType, Product} from '@nuskin/ns-product-lib';
3
- import {RunConfigService, events, BrowserDetection, UrlService} from '@nuskin/ns-util';
4
- import {AccountManager} from '@nuskin/ns-account';
3
+ import {RunConfigService, events, util, BrowserDetection, UrlService} from '@nuskin/ns-util';
4
+ import {UserService, AccountManager} from '@nuskin/ns-account';
5
5
  import ProductStatusService from '../product/ProductStatusService.js';
6
6
  import _ from 'lodash';
7
7
  import { getConfiguration } from '@nuskin/configuration-sdk';
8
- import {productLib} from '@nuskin/product-lib';
8
+ import { getProductBySku as getCsProductBySku } from './csProductHelper.js';
9
+ import axios from 'axios';
9
10
 
10
11
  let ProductService = function() {
11
12
  // ---------------------------------------------
@@ -21,24 +22,13 @@ let ProductService = function() {
21
22
  * @returns {null}
22
23
  */
23
24
  getProductBySku: async function(_options) {
24
- let options = verifyLocaleFields(_options),
25
- promises = [getProductDetail(options)];
26
-
27
- promises.push(getProductStatus(options));
28
-
29
- let values = await Promise.all(promises);
30
-
31
- let result = await handleDetailResponse(values[0], options);
32
-
33
- if (values[1] && values[1][0]) {
34
- handleStatusResponse(result.product, values[1][0], options);
25
+ const options = verifyLocaleFields(_options)
26
+ const {Cart: cartCfg} = await getConfiguration(['Cart']);
27
+ if (cartCfg.useContentStackProductData) {
28
+ return await getCsProductBySku(options)
35
29
  } else {
36
- // Fallback for product quantity on a failed product status call.
37
- // This is done to prevent the product detail component from locking up unnecessarily.
38
- result.product.availableQuantity = 10000;
30
+ return await legacyGetProductBySku(options);
39
31
  }
40
-
41
- return result;
42
32
  },
43
33
 
44
34
  /**
@@ -84,22 +74,42 @@ let ProductService = function() {
84
74
  // Private Methods
85
75
  //
86
76
  // ---------------------------------------------
77
+ async function legacyGetProductBySku(options) {
78
+ const promises = [getProductDetail(options)];
79
+
80
+ promises.push(getProductStatus(options));
81
+
82
+ let values = await Promise.all(promises);
83
+
84
+ let result = await handleDetailResponse(values[0], options);
85
+
86
+ if (values[1] && values[1][0]) {
87
+ handleStatusResponse(result.product, values[1][0], options);
88
+ } else {
89
+ // Fallback for product quantity on a failed product status call.
90
+ // This is done to prevent the product detail component from locking up unnecessarily.
91
+ result.product.availableQuantity = 10000;
92
+ }
93
+
94
+ return result;
95
+ }
96
+
87
97
  async function getProductDetail(_options) {
88
98
  let options = _options;
89
- let response;
99
+ let url = await getSkuSearchUrl(options);
100
+ let data;
90
101
 
91
102
  // Hit the PMD and get all the data for the product including the price information.
103
+ // Example url: https://test.nuskin.com/content/products/01/00/34/01003440.service.US.json
92
104
  try {
93
- response = await productLib.getProduct({
94
- fromId: options.sku,
95
- env: RunConfigService.getEnvironmentCode(),
96
- market: options.country,
97
- language: options.language
105
+ data = await axios({
106
+ method: 'GET',
107
+ url
98
108
  })
99
109
  } catch (e) {
100
- throw {error: e, failedSku: options.sku, type: events.errors.PRODUCT_LOOKUP};
110
+ throw {error: e, url: url, failedSku: options.sku, type: events.errors.PRODUCT_LOOKUP};
101
111
  }
102
- return response.data;
112
+ return data.data;
103
113
  }
104
114
 
105
115
  function getProductStatus(_options) {
@@ -125,6 +135,36 @@ let ProductService = function() {
125
135
  );
126
136
  }
127
137
 
138
+ async function getSkuSearchUrl(options) {
139
+ let firstTwo = options.sku.substring(0, 2),
140
+ secondTwo = options.sku.substring(2, 4),
141
+ thirdTwo = options.sku.substring(4, 6),
142
+ runConfig = RunConfigService.getRunConfig(),
143
+ query = '',
144
+ skuSearchUrl;
145
+
146
+ const {Url: urlCfg} = await getConfiguration(['Url']);
147
+ skuSearchUrl = urlCfg.skuSearchUrl;
148
+
149
+ if (runConfig.baseUrl !== '' && !skuSearchUrl.startsWith('http')) {
150
+ query = runConfig.baseUrl;
151
+ }
152
+
153
+ if (UserService.isLTOSite()){
154
+ query += util.getSiteConfig().urls.skuSearchUrl[0].replace('{firstTwo}', firstTwo);
155
+ }
156
+ else{
157
+ query += skuSearchUrl.replace('{firstTwo}', firstTwo);
158
+ }
159
+
160
+ query = query.replace('{secondTwo}', secondTwo);
161
+ query = query.replace('{thirdTwo}', thirdTwo);
162
+ query = query.replace('{sku}', options.sku);
163
+ query = query.replace('{countryCd}', options.cntryCd ? options.cntryCd : options.country);
164
+
165
+ return query;
166
+ }
167
+
128
168
  async function handleDetailResponse(responseData, options) {
129
169
  let retVal = {success: true},
130
170
  dataForProduct = createDataFromSkuSearch(responseData, options);
@@ -1,10 +1,8 @@
1
- import OrderAdapter from '../order/orderAdapter';
2
1
  import {getCachedConfiguration} from '@nuskin/configuration-sdk';
3
2
  import {Order} from '@nuskin/order-model';
4
3
  import {RunConfigService} from '@nuskin/ns-util';
5
- // import {CartService} from '@nuskin/ns-shop';
4
+ import {OrderManager, CartService, OrderType, OrderAdapter} from '../shop';
6
5
  import axios from 'axios';
7
- import { OrderManager } from '../shop';
8
6
 
9
7
  let PickupUtil = function() {
10
8
  'use strict';
@@ -142,6 +140,20 @@ let PickupUtil = function() {
142
140
  return markers;
143
141
  }
144
142
 
143
+ function getOrderValue() {
144
+ let value = 0;
145
+ const orderType = OrderManager.getOrder().orderType;
146
+ const cartInfo = CartService.getCartInfo();
147
+
148
+ if (orderType === OrderType.SINGLE_ORDER) {
149
+ value = cartInfo.totalOrderPrice;
150
+ } else {
151
+ value = cartInfo.totalOrderPrice + cartInfo.totalAdrPrice;
152
+ }
153
+
154
+ return value;
155
+ }
156
+
145
157
  function getUrl() {
146
158
  switch (RunConfigService.getEnvironmentCode()) {
147
159
  case 'dev':
@@ -164,7 +176,6 @@ let PickupUtil = function() {
164
176
  const {metapackMarket, metapackZipExclusions} = getCachedConfiguration('Checkout');
165
177
 
166
178
  if (metapackMarket) {
167
- const order = OrderManager.getOrder();
168
179
  let includePickupPoints = true;
169
180
  for (const zipRegEx of metapackZipExclusions || []) {
170
181
  const regEx = new RegExp(zipRegEx);
@@ -176,7 +187,8 @@ let PickupUtil = function() {
176
187
  {
177
188
  order,
178
189
  pudo: includePickupPoints,
179
- orderValue: order && order.orderTotals && order.orderTotals.grandTotal || 0.0
190
+ orderValue: getOrderValue(),
191
+ dangerousGoods: CartService.hasDangerousGoods()
180
192
  },
181
193
  {
182
194
  headers: {