@nuskin/ns-shop 7.0.5-cx1-13272.1 → 7.0.5-cx1-13272.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 +1 -1
- package/src/cart/cart.js +4 -0
- package/src/cart/cartService.js +13 -2
- package/src/order/orderAdapter.js +10 -2
- package/src/salesEventService.js +27 -12
package/package.json
CHANGED
package/src/cart/cart.js
CHANGED
|
@@ -863,6 +863,7 @@ export default function Cart(cartData) {
|
|
|
863
863
|
};
|
|
864
864
|
|
|
865
865
|
this.setMissingEventNames = async (order) => {
|
|
866
|
+
let cartUpdated = false;
|
|
866
867
|
const orderItems = this.getItems({cartOrderItems: true});
|
|
867
868
|
let nameSet = new Set();
|
|
868
869
|
let itemsChecked = [];
|
|
@@ -881,6 +882,7 @@ export default function Cart(cartData) {
|
|
|
881
882
|
if (itemEvents.includes(ien)) {
|
|
882
883
|
// set this items eventName if another item already has it set.
|
|
883
884
|
item.product.eventName = ien;
|
|
885
|
+
cartUpdated = true;
|
|
884
886
|
}
|
|
885
887
|
return !!item.product.eventName; // causes loop to stop if true
|
|
886
888
|
});
|
|
@@ -902,6 +904,7 @@ export default function Cart(cartData) {
|
|
|
902
904
|
itemEvents.some((ie) => {
|
|
903
905
|
if (eventStatuses[ie]) {
|
|
904
906
|
// set the status if event is active.
|
|
907
|
+
cartUpdated = true;
|
|
905
908
|
item.product.eventName == ie;
|
|
906
909
|
SalesEventService.logAnalyticInfo(
|
|
907
910
|
'cart-eventname-fixed', ie,
|
|
@@ -912,6 +915,7 @@ export default function Cart(cartData) {
|
|
|
912
915
|
})
|
|
913
916
|
});
|
|
914
917
|
}
|
|
918
|
+
return cartUpdated;
|
|
915
919
|
}
|
|
916
920
|
|
|
917
921
|
this.getCartInfo = function(options) {
|
package/src/cart/cartService.js
CHANGED
|
@@ -229,10 +229,21 @@ function updateItemPrices() {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
async function checkForMissingEventNames(order) {
|
|
232
|
+
let outOfSync = false;
|
|
232
233
|
await awaitForConfig();
|
|
233
234
|
const cart = _getCart();
|
|
234
|
-
|
|
235
|
+
|
|
236
|
+
// check to see if cart item has eventName but sapItem does not.
|
|
237
|
+
const orderItems = cart.getItems({cartOrderItems: true});
|
|
238
|
+
orderItems.map((item) => {
|
|
239
|
+
const sapItem = order.sapItems.find((sapItem) => sapItem.key === item.key);
|
|
240
|
+
if (sapItem && item.eventName && !sapItem.eventName)
|
|
241
|
+
outOfSync = true;
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
let updated = await cart.setMissingEventNames(order);
|
|
235
245
|
setCart(cart);
|
|
246
|
+
return updated || outOfSync;
|
|
236
247
|
}
|
|
237
248
|
|
|
238
249
|
function getCartProperty(key) {
|
|
@@ -1411,7 +1422,7 @@ const cartServiceConfigCallback = async (configs) => {
|
|
|
1411
1422
|
activeEvents = _activeEvents;
|
|
1412
1423
|
const cart = _getCart();
|
|
1413
1424
|
if (cart.updateEventPrices(activeEvents)) {
|
|
1414
|
-
events.setValue(events.shop.CART_EVENT_PRICE_UPDATED);
|
|
1425
|
+
events.setValue(events.shop.CART_EVENT_PRICE_UPDATED, [activeEvents]);
|
|
1415
1426
|
setCart(cart);
|
|
1416
1427
|
}
|
|
1417
1428
|
}
|
|
@@ -530,7 +530,8 @@ async function addSapItem(newItem, sapItem, sapSkus, adr, isAdrItem, replace) {
|
|
|
530
530
|
handleRedetermination(product, sapItem, sapSkus, adr, isAdrItem); // removes items from sapSkus
|
|
531
531
|
|
|
532
532
|
// Only honor the OneTime flag from SAP if we are a ADR order
|
|
533
|
-
|
|
533
|
+
const savedEventName = product.eventName;
|
|
534
|
+
const item = await CartService.addProductToCart({
|
|
534
535
|
product: product,
|
|
535
536
|
qty: sapItem.LineItem.RequestedQuantity,
|
|
536
537
|
adr: (adr && isAdrItem),
|
|
@@ -541,6 +542,11 @@ async function addSapItem(newItem, sapItem, sapSkus, adr, isAdrItem, replace) {
|
|
|
541
542
|
isBusinessPortfolio: newItem.businessPortfolio,
|
|
542
543
|
replace: replace
|
|
543
544
|
})
|
|
545
|
+
|
|
546
|
+
// eventName would have gotten nulled out. Fix it here.
|
|
547
|
+
product.eventName = savedEventName;
|
|
548
|
+
|
|
549
|
+
return item;
|
|
544
550
|
}
|
|
545
551
|
|
|
546
552
|
const syncProductItems = async (order, sapProducts, adr, includeSapItems) => {
|
|
@@ -600,6 +606,7 @@ const syncProductItems = async (order, sapProducts, adr, includeSapItems) => {
|
|
|
600
606
|
newItem.priceType = ShopContextService.getPriceType(isAdrItem);
|
|
601
607
|
newItem.pv = sapItem.PSV;
|
|
602
608
|
newItem.backOrderDate = sapItem.BackorderAvailableDate;
|
|
609
|
+
newItem.eventName = sapItem.LineItem.Event;
|
|
603
610
|
|
|
604
611
|
if (sapItem.LineItem.Custom) {
|
|
605
612
|
let code = null, name = null, label = null;
|
|
@@ -634,7 +641,7 @@ const syncProductItems = async (order, sapProducts, adr, includeSapItems) => {
|
|
|
634
641
|
newItem.isBusinessPortfolio = matchedItem.isBusinessPortfolio;
|
|
635
642
|
newItem.redeem = matchedItem.redeem;
|
|
636
643
|
newItem.qtyRedeemWithPoints = matchedItem.qtyRedeemWithPoints;
|
|
637
|
-
newItem.eventName = matchedItem.eventName;
|
|
644
|
+
newItem.eventName = !newItem.eventName ? matchedItem.eventName : newItem.eventName;
|
|
638
645
|
}
|
|
639
646
|
if (existingItem) {
|
|
640
647
|
newItem.thumbnail = existingItem.thumbnail;
|
|
@@ -1107,6 +1114,7 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
|
|
|
1107
1114
|
await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
|
|
1108
1115
|
syncOrderTotals(salesOrderDetail.OrderTotals, order.orderTotals);
|
|
1109
1116
|
syncPayment(salesOrderDetail.Payment, order.selectedPayment);
|
|
1117
|
+
OrderManager.saveOrders();
|
|
1110
1118
|
return order;
|
|
1111
1119
|
};
|
|
1112
1120
|
|
package/src/salesEventService.js
CHANGED
|
@@ -297,7 +297,7 @@ function _checkStatus(eventTicketInfo, useServerWaitTime) {
|
|
|
297
297
|
[ticket.eventName, eventTicketInfo.paused, {fromServer: useServerWaitTime, waitTime: actualWait}]
|
|
298
298
|
);
|
|
299
299
|
|
|
300
|
-
eventInfo.timerId = setTimeout(
|
|
300
|
+
eventInfo.timerId = setTimeout(_timerCallback(ticket.eventName), timerWait);
|
|
301
301
|
if (useServerWaitTime && timerWait < 30000) {
|
|
302
302
|
// if the wait time is base off of what the server passed back then
|
|
303
303
|
// don't call the server to update the ticket at the end of this timer
|
|
@@ -317,7 +317,7 @@ function _checkStatus(eventTicketInfo, useServerWaitTime) {
|
|
|
317
317
|
[ticket.eventName, eventTicketInfo.paused, {fromServer: useServerWaitTime, waitTime: actualWait}]
|
|
318
318
|
);
|
|
319
319
|
logAnalyticInfo('in-event', ticket.eventName);
|
|
320
|
-
eventInfo.timerId = setTimeout(
|
|
320
|
+
eventInfo.timerId = setTimeout(_timerCallback(ticket.eventName), timerWait);
|
|
321
321
|
} else {
|
|
322
322
|
_changeStatus(eventTicketInfo, POST_EVENT);
|
|
323
323
|
_checkStatus(eventTicketInfo, false); // to send post event and clear ticket.
|
|
@@ -686,6 +686,15 @@ function _getHeaders() {
|
|
|
686
686
|
};
|
|
687
687
|
}
|
|
688
688
|
|
|
689
|
+
async function _getActiveEvents() {
|
|
690
|
+
let response = await axios({
|
|
691
|
+
method: 'GET',
|
|
692
|
+
url: `${_getAwsUrl()}?activeWithin=${ACTIVE_EVENT_WITHIN}`,
|
|
693
|
+
headers: _getHeaders()
|
|
694
|
+
});
|
|
695
|
+
return response.data.salesEventResponse
|
|
696
|
+
}
|
|
697
|
+
|
|
689
698
|
//=========================================================================================================//
|
|
690
699
|
//
|
|
691
700
|
// Misc functions
|
|
@@ -815,17 +824,18 @@ async function _initializePolling() {
|
|
|
815
824
|
intervalCnt = 1;
|
|
816
825
|
|
|
817
826
|
intervalId = setInterval(async () => {
|
|
818
|
-
|
|
827
|
+
const now = Date.now();
|
|
828
|
+
const slept = now > (lastTime + TIMEOUT + 3000)
|
|
819
829
|
|
|
820
830
|
// if polling market config, only reload it every 30 seconds
|
|
821
|
-
if (pollMarketConfig && intervalCnt % 3 === 0) {
|
|
831
|
+
if (slept || pollMarketConfig && intervalCnt % 3 === 0) {
|
|
822
832
|
await _loadMarketEventConfig(true);
|
|
823
833
|
_marketStatusCheck();
|
|
824
834
|
}
|
|
825
835
|
intervalCnt++;
|
|
826
836
|
|
|
827
837
|
// if been to sleep for more then 3 seconds then check all ticket statuses.
|
|
828
|
-
if (
|
|
838
|
+
if (slept) {
|
|
829
839
|
// Went to sleep for 3 seconds or more
|
|
830
840
|
Object.values(eventTicketInfoMap).forEach(eventTicketInfo => {
|
|
831
841
|
// A new timer needs to be set, clear current one if exists
|
|
@@ -838,7 +848,17 @@ async function _initializePolling() {
|
|
|
838
848
|
_checkStatus(eventTicketInfo, false);
|
|
839
849
|
});
|
|
840
850
|
|
|
841
|
-
|
|
851
|
+
// check for missing tickets
|
|
852
|
+
if (slept) {
|
|
853
|
+
const activeEvents = await _getActiveEvents();
|
|
854
|
+
for (const eventInfo of activeEvents) {
|
|
855
|
+
if (mktEventConfigMap[eventInfo.eventName] && !eventTicketInfoMap[eventInfo.eventName]) {
|
|
856
|
+
await _initEventTicketInfo(eventInfo.eventName);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
lastTime = Date.now();
|
|
842
862
|
}, TIMEOUT);
|
|
843
863
|
}
|
|
844
864
|
}
|
|
@@ -989,12 +1009,7 @@ async function _loadAwsActiveEvents(country) {
|
|
|
989
1009
|
storageObj = {events: []};
|
|
990
1010
|
storage.setItem(activeEventsName, storageObj, {ttl: 250}); // to prevent multiple calls.
|
|
991
1011
|
try {
|
|
992
|
-
|
|
993
|
-
method: 'GET',
|
|
994
|
-
url: `${_getAwsUrl()}?activeWithin=${ACTIVE_EVENT_WITHIN}`,
|
|
995
|
-
headers: _getHeaders()
|
|
996
|
-
});
|
|
997
|
-
addEvents(response.data.salesEventResponse);
|
|
1012
|
+
addEvents(await _getActiveEvents());
|
|
998
1013
|
} catch (e) {
|
|
999
1014
|
// an error occurred with the call, clear active events
|
|
1000
1015
|
// so it won't wait 30 minutes to try again
|