@nuskin/ns-shop 6.4.14 → 6.4.15
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 +1 -1
- package/src/cart/productService.js +25 -62
package/package.json
CHANGED
|
@@ -4,7 +4,8 @@ import {RunConfigService, util, events, BrowserDetection, UrlService} from '@nus
|
|
|
4
4
|
import {UserService, AccountManager} from '@nuskin/ns-account';
|
|
5
5
|
import ProductStatusService from '../product/ProductStatusService.js';
|
|
6
6
|
import _ from 'lodash';
|
|
7
|
-
import {
|
|
7
|
+
import { getConfiguration } from '@nuskin/configuration-sdk';
|
|
8
|
+
import axios from 'axios';
|
|
8
9
|
|
|
9
10
|
let ProductService = function() {
|
|
10
11
|
// ---------------------------------------------
|
|
@@ -27,7 +28,7 @@ let ProductService = function() {
|
|
|
27
28
|
|
|
28
29
|
let values = await Promise.all(promises);
|
|
29
30
|
|
|
30
|
-
let result = handleDetailResponse(values[0], options);
|
|
31
|
+
let result = await handleDetailResponse(values[0], options);
|
|
31
32
|
|
|
32
33
|
if (values[1] && values[1][0]) {
|
|
33
34
|
handleStatusResponse(result.product, values[1][0], options);
|
|
@@ -40,20 +41,6 @@ let ProductService = function() {
|
|
|
40
41
|
return result;
|
|
41
42
|
},
|
|
42
43
|
|
|
43
|
-
getProductsBySkus: function(options, callbackFn) {
|
|
44
|
-
let deferred = [];
|
|
45
|
-
|
|
46
|
-
for (let i = 0; i < options.skus.length; i++) {
|
|
47
|
-
deferred.push(
|
|
48
|
-
$.ajaxWrapper.getJson(getSkuSearchUrl({
|
|
49
|
-
sku: options.skus[i],
|
|
50
|
-
cntryCd: options.country,
|
|
51
|
-
language: options.language}), null, null, 0).getJqXHR()
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
$.when.apply(this, deferred).then(multiProductCallback(options, callbackFn));
|
|
55
|
-
},
|
|
56
|
-
|
|
57
44
|
/**
|
|
58
45
|
* Retrieves product data from PMD - /content/products
|
|
59
46
|
* Full URL used to get product data ex. https://test.nuskin.com/content/products/01/11/11/01111155/en.service.US.json
|
|
@@ -88,7 +75,7 @@ let ProductService = function() {
|
|
|
88
75
|
});
|
|
89
76
|
|
|
90
77
|
|
|
91
|
-
|
|
78
|
+
|
|
92
79
|
}
|
|
93
80
|
};
|
|
94
81
|
|
|
@@ -97,28 +84,22 @@ let ProductService = function() {
|
|
|
97
84
|
// Private Methods
|
|
98
85
|
//
|
|
99
86
|
// ---------------------------------------------
|
|
100
|
-
function getProductDetail(_options) {
|
|
87
|
+
async function getProductDetail(_options) {
|
|
101
88
|
let options = _options;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
0
|
|
117
|
-
);
|
|
118
|
-
} catch (e) {
|
|
119
|
-
reject({error: e, url: url, failedSku: options.sku, type: events.errors.PRODUCT_LOOKUP});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
89
|
+
let url = await getSkuSearchUrl(options);
|
|
90
|
+
let data;
|
|
91
|
+
|
|
92
|
+
// Hit the PMD and get all the data for the product including the price information.
|
|
93
|
+
// Example url: https://test.nuskin.com/content/products/01/00/34/01003440.service.US.json
|
|
94
|
+
try {
|
|
95
|
+
data = await axios({
|
|
96
|
+
method: 'GET',
|
|
97
|
+
url
|
|
98
|
+
})
|
|
99
|
+
} catch (e) {
|
|
100
|
+
throw {error: e, url: url, failedSku: options.sku, type: events.errors.PRODUCT_LOOKUP};
|
|
101
|
+
}
|
|
102
|
+
return data.data;
|
|
122
103
|
}
|
|
123
104
|
|
|
124
105
|
function getProductStatus(_options) {
|
|
@@ -144,7 +125,7 @@ let ProductService = function() {
|
|
|
144
125
|
);
|
|
145
126
|
}
|
|
146
127
|
|
|
147
|
-
function getSkuSearchUrl(options) {
|
|
128
|
+
async function getSkuSearchUrl(options) {
|
|
148
129
|
let firstTwo = options.sku.substring(0, 2),
|
|
149
130
|
secondTwo = options.sku.substring(2, 4),
|
|
150
131
|
thirdTwo = options.sku.substring(4, 6),
|
|
@@ -152,7 +133,8 @@ let ProductService = function() {
|
|
|
152
133
|
query = '',
|
|
153
134
|
skuSearchUrl;
|
|
154
135
|
|
|
155
|
-
|
|
136
|
+
const {Url: urlCfg} = await getConfiguration(['Url']);
|
|
137
|
+
skuSearchUrl = urlCfg.skuSearchUrl;
|
|
156
138
|
|
|
157
139
|
if (runConfig.baseUrl !== '' && !skuSearchUrl.startsWith('http')) {
|
|
158
140
|
query = runConfig.baseUrl;
|
|
@@ -173,7 +155,7 @@ let ProductService = function() {
|
|
|
173
155
|
return query;
|
|
174
156
|
}
|
|
175
157
|
|
|
176
|
-
function handleDetailResponse(responseData, options) {
|
|
158
|
+
async function handleDetailResponse(responseData, options) {
|
|
177
159
|
let retVal = {success: true},
|
|
178
160
|
dataForProduct = createDataFromSkuSearch(responseData, options);
|
|
179
161
|
|
|
@@ -202,7 +184,8 @@ let ProductService = function() {
|
|
|
202
184
|
}
|
|
203
185
|
|
|
204
186
|
if (retVal.product && options.priceType) {
|
|
205
|
-
const
|
|
187
|
+
const {Cart: cartCfg} = await getConfiguration(['Cart']);
|
|
188
|
+
const priceType = cartCfg.showWholeSalePricing && !AccountManager.isLoggedIn()
|
|
206
189
|
? PriceType.WWHL
|
|
207
190
|
: options.priceType;
|
|
208
191
|
retVal.product.setPriceAndPvFromType(priceType);
|
|
@@ -219,26 +202,6 @@ let ProductService = function() {
|
|
|
219
202
|
}
|
|
220
203
|
}
|
|
221
204
|
|
|
222
|
-
function multiProductCallback(_options, _callbackFn) {
|
|
223
|
-
let options = _options,
|
|
224
|
-
callbackFn = _callbackFn;
|
|
225
|
-
return function() {
|
|
226
|
-
let retData = {};
|
|
227
|
-
if (callbackFn) {
|
|
228
|
-
if (arguments[0]) {
|
|
229
|
-
if (arguments[0][0]) {
|
|
230
|
-
for (let i = 0; i < arguments.length; i++) {
|
|
231
|
-
retData[arguments[i][0].sku] = createDataFromSkuSearch(arguments[i][0], options);
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
retData[arguments[0].sku] = createDataFromSkuSearch(arguments[0], options);
|
|
235
|
-
}
|
|
236
|
-
callbackFn(retData);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
205
|
function createDataFromSkuSearch(searchData, options) {
|
|
243
206
|
if (_.isEmpty(searchData)) {
|
|
244
207
|
return new Product();
|