@nuskin/ns-shop 7.0.11-CodeFix.1 → 7.0.11-pur-813.1
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-
|
|
3
|
+
"version": "7.0.11-pur-813.1",
|
|
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": {
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"@nuskin/ns-loyalty-web": "1.5.6",
|
|
29
29
|
"@nuskin/ns-product-lib": "2.17.6",
|
|
30
30
|
"@nuskin/nuskinjquery": "2.3.1",
|
|
31
|
+
"@nuskin/order-model": "3.1.3",
|
|
32
|
+
"@nuskin/product-lib": "2.2.1",
|
|
31
33
|
"axios": "1.6.5",
|
|
32
34
|
"decimal.js": "10.4.3",
|
|
33
35
|
"jp-conversion": "0.0.7",
|
|
@@ -404,7 +404,7 @@ function _assembleChildSkus(requestData, options) {
|
|
|
404
404
|
if(personalOffer != null && productWithVariant.length > 0 && productWithVariant[0].variantSelected){
|
|
405
405
|
selectedVariants = productWithVariant[0].variantSelected;
|
|
406
406
|
}
|
|
407
|
-
if (personalOffer != null && selectedVariants && cs.skuId != selectedVariants[cs.productId] && (cs.type !== "BUNDLE" && cs.type !== "OPTIONAL"
|
|
407
|
+
if (personalOffer != null && selectedVariants && cs.skuId != selectedVariants[cs.productId] && (cs.type !== "BUNDLE" && cs.type !== "OPTIONAL")) return null
|
|
408
408
|
const childSku =
|
|
409
409
|
(personalOffer != null && selectedVariants && selectedVariants[cs.productId] && config.MySite_graphql_active)
|
|
410
410
|
? {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import $ from '@nuskin/nuskinjquery';
|
|
2
2
|
import {PriceType, Product} from '@nuskin/ns-product-lib';
|
|
3
|
-
import {RunConfigService,
|
|
4
|
-
import {
|
|
3
|
+
import {RunConfigService, events, BrowserDetection, UrlService} from '@nuskin/ns-util';
|
|
4
|
+
import {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
|
|
8
|
+
import {productLib} from '@nuskin/product-lib';
|
|
9
9
|
|
|
10
10
|
let ProductService = function() {
|
|
11
11
|
// ---------------------------------------------
|
|
@@ -86,20 +86,20 @@ let ProductService = function() {
|
|
|
86
86
|
// ---------------------------------------------
|
|
87
87
|
async function getProductDetail(_options) {
|
|
88
88
|
let options = _options;
|
|
89
|
-
let
|
|
90
|
-
let data;
|
|
89
|
+
let response;
|
|
91
90
|
|
|
92
91
|
// 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
92
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
response = await productLib.getProduct({
|
|
94
|
+
fromId: options.sku,
|
|
95
|
+
env: RunConfigService.getEnvironmentCode(),
|
|
96
|
+
market: options.country,
|
|
97
|
+
language: options.language
|
|
98
98
|
})
|
|
99
99
|
} catch (e) {
|
|
100
|
-
throw {error: e,
|
|
100
|
+
throw {error: e, failedSku: options.sku, type: events.errors.PRODUCT_LOOKUP};
|
|
101
101
|
}
|
|
102
|
-
return
|
|
102
|
+
return response.data;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
function getProductStatus(_options) {
|
|
@@ -125,36 +125,6 @@ let ProductService = function() {
|
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
async function getSkuSearchUrl(options) {
|
|
129
|
-
let firstTwo = options.sku.substring(0, 2),
|
|
130
|
-
secondTwo = options.sku.substring(2, 4),
|
|
131
|
-
thirdTwo = options.sku.substring(4, 6),
|
|
132
|
-
runConfig = RunConfigService.getRunConfig(),
|
|
133
|
-
query = '',
|
|
134
|
-
skuSearchUrl;
|
|
135
|
-
|
|
136
|
-
const {Url: urlCfg} = await getConfiguration(['Url']);
|
|
137
|
-
skuSearchUrl = urlCfg.skuSearchUrl;
|
|
138
|
-
|
|
139
|
-
if (runConfig.baseUrl !== '' && !skuSearchUrl.startsWith('http')) {
|
|
140
|
-
query = runConfig.baseUrl;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (UserService.isLTOSite()){
|
|
144
|
-
query += util.getSiteConfig().urls.skuSearchUrl[0].replace('{firstTwo}', firstTwo);
|
|
145
|
-
}
|
|
146
|
-
else{
|
|
147
|
-
query += skuSearchUrl.replace('{firstTwo}', firstTwo);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
query = query.replace('{secondTwo}', secondTwo);
|
|
151
|
-
query = query.replace('{thirdTwo}', thirdTwo);
|
|
152
|
-
query = query.replace('{sku}', options.sku);
|
|
153
|
-
query = query.replace('{countryCd}', options.cntryCd ? options.cntryCd : options.country);
|
|
154
|
-
|
|
155
|
-
return query;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
128
|
async function handleDetailResponse(responseData, options) {
|
|
159
129
|
let retVal = {success: true},
|
|
160
130
|
dataForProduct = createDataFromSkuSearch(responseData, options);
|
|
@@ -5,6 +5,7 @@ import {RunConfigService, events, util, PersonalOfferStorageService, BrowserDete
|
|
|
5
5
|
import {getCachedConfigField} from '@nuskin/configuration-sdk';
|
|
6
6
|
import {UserService} from "@nuskin/ns-account";
|
|
7
7
|
import PaymentAdapter from '../payment/PaymentAdapter';
|
|
8
|
+
import pickupUtil from '../shipping/pickupUtil';
|
|
8
9
|
|
|
9
10
|
let splitLineItems = [];
|
|
10
11
|
|
|
@@ -865,13 +866,14 @@ let setSelectedShipMethod = function(order, matchMethod = {}) {
|
|
|
865
866
|
|
|
866
867
|
/**
|
|
867
868
|
* Parses pickup points from SAP response, in case shipping method is set to pickup points!
|
|
868
|
-
* @param {Object[]}
|
|
869
|
+
* @param {Object[]} oldPup The Custom array on the salesorderrequest
|
|
870
|
+
* @param {Object[]} newPup The Custom array on the salesorderrequest
|
|
869
871
|
* @param {Object} order
|
|
870
872
|
*/
|
|
871
|
-
function setPickupPoints(
|
|
872
|
-
const pupLocations =
|
|
873
|
+
function setPickupPoints(oldPup, newPup, order) {
|
|
874
|
+
const pupLocations = oldPup || [];
|
|
873
875
|
if (order.selectedShippingMethod && PickupUtil.supports(order.selectedShippingMethod.Code)) {
|
|
874
|
-
order.pickupPoints = PickupUtil.parse(pupLocations);
|
|
876
|
+
order.pickupPoints = newPup ? newPup : PickupUtil.parse(pupLocations);
|
|
875
877
|
if (order.selectedPickupPoint) {
|
|
876
878
|
order.selectedPickupPoint = order.pickupPoints.find(pickupPoint => order.selectedPickupPoint.id === pickupPoint.id);
|
|
877
879
|
}
|
|
@@ -1090,13 +1092,19 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
|
|
|
1090
1092
|
}
|
|
1091
1093
|
|
|
1092
1094
|
if (salesOrderDetail.ShippingAvailableMethods && salesOrderDetail.ShippingAvailableMethods.length > 0) {
|
|
1093
|
-
|
|
1095
|
+
const useShipMethodsApi = getCachedConfigField('useShipMethodsApi');
|
|
1096
|
+
const shipMethods = useShipMethodsApi ? await pickupUtil.getShipMethods() : salesOrderDetail.ShippingAvailableMethods;
|
|
1097
|
+
order.shippingAvailableMethods = sortShippingAvailableMethods(shipMethods);
|
|
1094
1098
|
setShippingAvailableMethodsPickupInfo(order.shippingAvailableMethods);
|
|
1095
1099
|
setSelectedShipMethod(order, salesOrderDetail.Shipping.ShippingMethod);
|
|
1096
1100
|
// When an order or ADR is created. The response from the create call is missing the list of pickup locations
|
|
1097
1101
|
// The list isn't needed in this case since the user has already created the order so we don't need to update the pickup points
|
|
1098
1102
|
if (!createResponse) {
|
|
1099
|
-
|
|
1103
|
+
let oldPup = null;
|
|
1104
|
+
if (!useShipMethodsApi) oldPup = salesOrderDetail.Custom;
|
|
1105
|
+
let newPup = null;
|
|
1106
|
+
if (useShipMethodsApi) newPup = await pickupUtil.getPickupPoints();
|
|
1107
|
+
setPickupPoints(oldPup, newPup, order);
|
|
1100
1108
|
}
|
|
1101
1109
|
}
|
|
1102
1110
|
shippingHack(order, salesOrderDetail.OrderTotals.Shipping, salesOrderDetail.Currency);
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import OrderAdapter from '../order/orderAdapter';
|
|
2
|
+
import {getCachedConfiguration} from '@nuskin/configuration-sdk';
|
|
3
|
+
import {Order} from '@nuskin/order-model';
|
|
4
|
+
import {RunConfigService} from '@nuskin/ns-util';
|
|
5
|
+
// import {CartService} from '@nuskin/ns-shop';
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import { OrderManager } from '../shop';
|
|
8
|
+
|
|
1
9
|
let PickupUtil = function() {
|
|
2
10
|
'use strict';
|
|
3
11
|
const SERVICE_GROUP = 'SERVICE_GROUP',
|
|
@@ -15,6 +23,10 @@ let PickupUtil = function() {
|
|
|
15
23
|
UNIT = 'UNIT',
|
|
16
24
|
CARRIER_CODE = 'CARRIER_CODE';
|
|
17
25
|
|
|
26
|
+
let promise = Promise.resolve();
|
|
27
|
+
let shipMethods = [];
|
|
28
|
+
let pickupPoints = [];
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* Pickup Point shipping methods.
|
|
20
32
|
* Values are shipping method codes.
|
|
@@ -130,12 +142,75 @@ let PickupUtil = function() {
|
|
|
130
142
|
return markers;
|
|
131
143
|
}
|
|
132
144
|
|
|
145
|
+
function getUrl() {
|
|
146
|
+
switch (RunConfigService.getEnvironmentCode()) {
|
|
147
|
+
case 'dev':
|
|
148
|
+
return 'https://ship-methods.api.dev.nuskin.com/v1';
|
|
149
|
+
case 'test':
|
|
150
|
+
return 'https://ship-methods.api.test.nuskin.com/v1';
|
|
151
|
+
case 'stage':
|
|
152
|
+
return 'https://ship-methods.api.dev.nuskin.com/v1';
|
|
153
|
+
case 'prod':
|
|
154
|
+
return 'https://ship-methods.api.dev.nuskin.com/v1';
|
|
155
|
+
default:
|
|
156
|
+
return 'https://ship-methods.api.dev.nuskin.com/v1';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function loadShipMethods() {
|
|
161
|
+
const order = Order.fromSalesOrderRequest(OrderAdapter.populateSalesOrder('SIMULATE'));
|
|
162
|
+
|
|
163
|
+
const postalCode = order.shippingPostalCode;
|
|
164
|
+
const {metapackMarket, metapackZipExclusions} = getCachedConfiguration('Checkout');
|
|
165
|
+
|
|
166
|
+
if (metapackMarket) {
|
|
167
|
+
const order = OrderManager.getOrder();
|
|
168
|
+
let includePickupPoints = true;
|
|
169
|
+
for (const zipRegEx of metapackZipExclusions || []) {
|
|
170
|
+
const regEx = new RegExp(zipRegEx);
|
|
171
|
+
includePickupPoints = includePickupPoints && !postalCode.match(regEx);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
promise = axios.post(
|
|
175
|
+
getUrl(),
|
|
176
|
+
{
|
|
177
|
+
order,
|
|
178
|
+
pudo: includePickupPoints,
|
|
179
|
+
orderValue: order && order.orderTotals && order.orderTotals.grandTotal || 0.0
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
headers: {
|
|
183
|
+
'Content-Type': 'application/json; charset=UTF-8'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
).then((results) => {
|
|
187
|
+
shipMethods = results.data.shipMethods;
|
|
188
|
+
pickupPoints = results.data.pickupPoints;
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function getShipMethods() {
|
|
194
|
+
await promise;
|
|
195
|
+
|
|
196
|
+
return shipMethods;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function getPickupPoints() {
|
|
200
|
+
await promise;
|
|
201
|
+
|
|
202
|
+
return pickupPoints;
|
|
203
|
+
}
|
|
204
|
+
|
|
133
205
|
return {
|
|
134
206
|
allMethods: shippingMethods,
|
|
135
207
|
supports: isPickupPointShippingMethod,
|
|
136
208
|
parse: parsePickupPoints,
|
|
137
209
|
bounds: getBounds,
|
|
138
|
-
markers: generateMarkers
|
|
210
|
+
markers: generateMarkers,
|
|
211
|
+
loadShipMethods,
|
|
212
|
+
getShipMethods,
|
|
213
|
+
getPickupPoints
|
|
139
214
|
}
|
|
140
215
|
}();
|
|
141
216
|
|