@nuskin/ns-shop 7.0.11-pur-813.5 → 7.0.11-pur-813.7
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
|
@@ -8,7 +8,7 @@ const extractProductData = (data, sku) => {
|
|
|
8
8
|
let retVal;
|
|
9
9
|
|
|
10
10
|
if (Array.isArray(data.variants) && data.variants.length > 0) {
|
|
11
|
-
retVal = data.variants.find((variant) => variant.sku === sku);
|
|
11
|
+
retVal = data.variants.find((variant) => variant.sku === sku) || data.variants[0];
|
|
12
12
|
retVal.variantSelectLabel = data.variantSelectLabel;
|
|
13
13
|
} else if (data.bundle) {
|
|
14
14
|
retVal = data.bundle;
|
|
@@ -262,6 +262,13 @@ const getProductBySku = async (options) => {
|
|
|
262
262
|
return result;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
+
const getProductData = async (options) => {
|
|
266
|
+
const data = await getProductDetail(options);
|
|
267
|
+
|
|
268
|
+
return createDataFromSkuSearch(data, options);
|
|
269
|
+
}
|
|
270
|
+
|
|
265
271
|
export {
|
|
266
|
-
getProductBySku
|
|
272
|
+
getProductBySku,
|
|
273
|
+
getProductData
|
|
267
274
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import $ from '@nuskin/nuskinjquery';
|
|
2
1
|
import {PriceType, Product} from '@nuskin/ns-product-lib';
|
|
3
2
|
import {RunConfigService, events, util, BrowserDetection, UrlService} from '@nuskin/ns-util';
|
|
4
3
|
import {UserService, AccountManager} from '@nuskin/ns-account';
|
|
5
4
|
import ProductStatusService from '../product/ProductStatusService.js';
|
|
6
5
|
import _ from 'lodash';
|
|
7
6
|
import { getConfiguration } from '@nuskin/configuration-sdk';
|
|
8
|
-
import { getProductBySku as getCsProductBySku } from './csProductHelper.js';
|
|
7
|
+
import { getProductBySku as getCsProductBySku, getProductData as getCsProductData } from './csProductHelper.js';
|
|
9
8
|
import axios from 'axios';
|
|
10
9
|
|
|
11
10
|
let ProductService = function() {
|
|
@@ -37,35 +36,48 @@ let ProductService = function() {
|
|
|
37
36
|
* @param {string} sku - ex. 01111155
|
|
38
37
|
* @returns {Promise}
|
|
39
38
|
*/
|
|
40
|
-
getProductData: function(sku, country, language) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if(
|
|
44
|
-
optionsData
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
reject(response);
|
|
39
|
+
getProductData: async function(sku, country, language) {
|
|
40
|
+
let retVal;
|
|
41
|
+
|
|
42
|
+
if (sku) {
|
|
43
|
+
const optionsData = {
|
|
44
|
+
country: country ? country : undefined,
|
|
45
|
+
language: language ? language : undefined,
|
|
46
|
+
sku
|
|
47
|
+
};
|
|
48
|
+
const options = verifyLocaleFields(optionsData);
|
|
49
|
+
const {Cart: cartCfg} = await getConfiguration(['Cart']);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
|
|
53
|
+
if (cartCfg.useContentStackProductData) {
|
|
54
|
+
retVal = await getCsProductData(options);
|
|
55
|
+
} else {
|
|
56
|
+
const tokenizedSku = tokenizeSku(sku);
|
|
57
|
+
const url = UrlService.getSiteUrl() + "/content/products/" + tokenizedSku + "/" +
|
|
58
|
+
options.language + ".service." + options.country + ".json";
|
|
59
|
+
const response = await axios.get(url);
|
|
60
|
+
retVal = createDataFromSkuSearch(response, options);
|
|
63
61
|
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error("There was a problem retrieving product data", err);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return retVal;
|
|
67
|
+
|
|
68
|
+
// return new Promise((resolve, reject) => {
|
|
69
|
+
// $.ajax({
|
|
70
|
+
// type: 'GET',
|
|
71
|
+
// url: url,
|
|
72
|
+
// success: function(response) {
|
|
73
|
+
// resolve(createDataFromSkuSearch(response, options));
|
|
74
|
+
// },
|
|
75
|
+
// error: function(response) {
|
|
76
|
+
// console.error("There was a problem retrieving product data:", response);
|
|
77
|
+
// reject(response);
|
|
78
|
+
// }
|
|
79
|
+
// });
|
|
80
|
+
// });
|
|
69
81
|
}
|
|
70
82
|
};
|
|
71
83
|
|
|
@@ -182,6 +182,7 @@ let PickupUtil = function() {
|
|
|
182
182
|
includePickupPoints = includePickupPoints && !postalCode.match(regEx);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
const runConfig = RunConfigService.getRunConfig();
|
|
185
186
|
promise = axios.post(
|
|
186
187
|
getUrl(),
|
|
187
188
|
{
|
|
@@ -189,7 +190,8 @@ let PickupUtil = function() {
|
|
|
189
190
|
pudo: includePickupPoints,
|
|
190
191
|
orderValue: getOrderValue(),
|
|
191
192
|
dangerousGoods: CartService.hasDangerousGoods(),
|
|
192
|
-
language:
|
|
193
|
+
language: runConfig.language,
|
|
194
|
+
country: runConfig.country
|
|
193
195
|
},
|
|
194
196
|
{
|
|
195
197
|
headers: {
|
|
@@ -199,7 +201,11 @@ let PickupUtil = function() {
|
|
|
199
201
|
).then((results) => {
|
|
200
202
|
shipMethods = results.data.shipMethods;
|
|
201
203
|
pickupPoints = results.data.pickupPoints;
|
|
202
|
-
})
|
|
204
|
+
}).catch((err) => {
|
|
205
|
+
console.log(err);
|
|
206
|
+
shipMethods = [];
|
|
207
|
+
pickupPoints = [];
|
|
208
|
+
});
|
|
203
209
|
}
|
|
204
210
|
}
|
|
205
211
|
|