Fix initial page load for tax
There's possibly some way to get the tax endpoint to fail with mobile fee but I can't recreate it consistently
This commit is contained in:
parent
1a99d1a985
commit
9aa2a95bcc
2 changed files with 47 additions and 85 deletions
|
|
@ -191,32 +191,16 @@ export default {
|
||||||
// Call APIs
|
// Call APIs
|
||||||
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
const cmsContentPromise = fetchCmsContentForPage(to.name);
|
||||||
|
|
||||||
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
let lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
||||||
|
|
||||||
const frontWipersOnOrder =
|
const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
lineItemsFromStore.vaps.filter(
|
storeActions.GET_WIPERS,
|
||||||
(wiper) => wiper.partType == partTypeStrings.FRONT_WIPER
|
{
|
||||||
) ?? [];
|
serviceZipCode: store.getters.order.serviceLocation.zipCode,
|
||||||
|
carId: store.getters.vehicle.carId,
|
||||||
const rearWipersOnOrder =
|
},
|
||||||
lineItemsFromStore.vaps.filter(
|
"payment-method"
|
||||||
(wiper) => wiper.partType == partTypeStrings.REAR_WIPER
|
);
|
||||||
) ?? [];
|
|
||||||
|
|
||||||
const orderHasFrontWipers = frontWipersOnOrder.length > 0;
|
|
||||||
const orderHasRearWipers = rearWipersOnOrder.length > 0;
|
|
||||||
|
|
||||||
const wipersPromise =
|
|
||||||
!orderHasFrontWipers || !orderHasRearWipers
|
|
||||||
? baseMixin.methods.dispatchStoreActionWithLogging(
|
|
||||||
storeActions.GET_WIPERS,
|
|
||||||
{
|
|
||||||
serviceZipCode: store.getters.order.serviceLocation.zipCode,
|
|
||||||
carId: store.getters.vehicle.carId,
|
|
||||||
},
|
|
||||||
"payment-method"
|
|
||||||
)
|
|
||||||
: Promise.resolve([]);
|
|
||||||
|
|
||||||
const rainDefensePromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
const rainDefensePromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.GET_RAIN_DEFENSE,
|
storeActions.GET_RAIN_DEFENSE,
|
||||||
|
|
@ -253,67 +237,53 @@ export default {
|
||||||
const supportingItems = lineItemsFromStore.supportingItems ?? [];
|
const supportingItems = lineItemsFromStore.supportingItems ?? [];
|
||||||
const vaps = lineItemsFromStore.vaps ?? [];
|
const vaps = lineItemsFromStore.vaps ?? [];
|
||||||
|
|
||||||
// if the order already has wipers on it from the quote page, use those as the available wipers
|
const availableVaps = [resultMap.rainDefense, ...resultMap.wipers];
|
||||||
// instead of what comes from the backend. This is to prevent issues with part interchange.
|
|
||||||
const availableFrontWipers = orderHasFrontWipers
|
|
||||||
? frontWipersOnOrder
|
|
||||||
: (resultMap.wipers.filter((wiper) => wiper.partType == partTypeStrings.FRONT_WIPER) ??
|
|
||||||
[]);
|
|
||||||
const availableRearWipers = orderHasRearWipers
|
|
||||||
? rearWipersOnOrder
|
|
||||||
: (resultMap.wipers.filter((wiper) => wiper.partType == partTypeStrings.REAR_WIPER) ??
|
|
||||||
[]);
|
|
||||||
|
|
||||||
const allLineItems = [
|
const pricedAvailableVaps = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
resultMap.rainDefense,
|
|
||||||
...supportingItems,
|
|
||||||
...availableFrontWipers,
|
|
||||||
...availableRearWipers,
|
|
||||||
...glassParts,
|
|
||||||
...vaps,
|
|
||||||
];
|
|
||||||
|
|
||||||
const lineItemsToTax = Array.from(
|
|
||||||
new Map(allLineItems.map((item) => [item.partNumber, item])).values()
|
|
||||||
);
|
|
||||||
|
|
||||||
const availableVaps = [
|
|
||||||
resultMap.rainDefense,
|
|
||||||
...availableFrontWipers,
|
|
||||||
...availableRearWipers,
|
|
||||||
];
|
|
||||||
|
|
||||||
const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging(
|
|
||||||
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||||
{
|
{
|
||||||
availableLineItems: lineItemsToTax,
|
availableLineItems: availableVaps,
|
||||||
},
|
},
|
||||||
"payment-method",
|
"payment-method",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const lineItemsOnOrderAndAvailableVaps = [
|
||||||
|
...pricedAvailableVaps,
|
||||||
|
...glassParts,
|
||||||
|
...supportingItems,
|
||||||
|
...vaps,
|
||||||
|
];
|
||||||
|
|
||||||
// Promo logic
|
// Promo logic
|
||||||
// Populate the previous state of promos for toast message usage in "next()"
|
// Populate the previous state of promos for toast message usage in "next()"
|
||||||
const oldActivePromos = store.getters.lineItems.promos?.slice(0);
|
const oldActivePromos = store.getters.lineItems.promos?.slice(0);
|
||||||
const oldInactivePromos = store.getters.order.payment.inactivePromos?.slice(0);
|
const oldInactivePromos = store.getters.order.payment.inactivePromos?.slice(0);
|
||||||
|
|
||||||
const promoCodeFromQueryString = consumeQueryFromStash(queryStrings.PROMO);
|
const promoCodeFromQueryString = consumeQueryFromStash(queryStrings.PROMO);
|
||||||
|
// New promos are saved to store with this
|
||||||
const { validatePromoResponse, revalidatePromoResponse } =
|
const { validatePromoResponse, revalidatePromoResponse } =
|
||||||
await revalidatePromosAndValidateQueryStringPromo(
|
await revalidatePromosAndValidateQueryStringPromo(
|
||||||
promoCodeFromQueryString,
|
promoCodeFromQueryString,
|
||||||
pricedLineItemsToTax,
|
lineItemsOnOrderAndAvailableVaps,
|
||||||
"payment-method"
|
"payment-method"
|
||||||
);
|
);
|
||||||
|
// update lineItemsFromStore with newly added promos
|
||||||
|
let lineItemsForCart = deepClone(store.getters.order.lineItems);
|
||||||
|
delete lineItemsForCart.serverData;
|
||||||
|
|
||||||
// Add newly validated promos to the array to get taxed
|
|
||||||
const newValidatedPromos = validatePromoResponse?.orderPromos ?? [];
|
|
||||||
newValidatedPromos.push(
|
|
||||||
...(revalidatePromoResponse ? revalidatePromoResponse.promoLineItems : [])
|
|
||||||
);
|
|
||||||
pricedLineItemsToTax.push(...newValidatedPromos);
|
|
||||||
// End of promo logic
|
// End of promo logic
|
||||||
|
//
|
||||||
|
|
||||||
const taxedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging(
|
const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||||
|
lineItemsForCart.promos ?? [],
|
||||||
|
availableVaps,
|
||||||
|
lineItemsForCart
|
||||||
|
);
|
||||||
|
lineItemsForCart.vaps = lineItemsForCart.vaps ?? [];
|
||||||
|
lineItemsForCart.vaps.push(...vapsToAddToCart);
|
||||||
|
// Tax items on order
|
||||||
|
lineItemsForCart = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||||
{
|
{
|
||||||
billToAccountNumber: store.getters.payment.billToAccountNumber,
|
billToAccountNumber: store.getters.payment.billToAccountNumber,
|
||||||
|
|
@ -322,31 +292,17 @@ export default {
|
||||||
serviceLocationCity: store.getters.order.serviceLocation.city,
|
serviceLocationCity: store.getters.order.serviceLocation.city,
|
||||||
serviceLocationState: store.getters.order.serviceLocation.state,
|
serviceLocationState: store.getters.order.serviceLocation.state,
|
||||||
serviceLocationZipCode: store.getters.order.serviceLocation.zipCode,
|
serviceLocationZipCode: store.getters.order.serviceLocation.zipCode,
|
||||||
pricedLineItems: pricedLineItemsToTax,
|
pricedLineItems: lineItemsForCart,
|
||||||
},
|
},
|
||||||
"payment-method",
|
"payment-method",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Match all line items to the line items as they are in the store
|
|
||||||
// and rebuild the original structure.
|
|
||||||
const lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, lineItemsFromStore);
|
|
||||||
const taxedVaps = mapTaxedLineItemsToStoreFormat(taxedLineItems, availableVaps);
|
|
||||||
|
|
||||||
lineItems.promos = newValidatedPromos ?? [];
|
|
||||||
const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos(
|
|
||||||
newValidatedPromos,
|
|
||||||
taxedVaps,
|
|
||||||
lineItems
|
|
||||||
);
|
|
||||||
lineItems.vaps = lineItems.vaps ?? [];
|
|
||||||
lineItems.vaps.push(...vapsToAddToCart);
|
|
||||||
|
|
||||||
// Call the "next" function to complete the transition to this page.
|
// Call the "next" function to complete the transition to this page.
|
||||||
next((vm) => {
|
next((vm) => {
|
||||||
vm.setCmsContent(resultMap.cmsContent);
|
vm.setCmsContent(resultMap.cmsContent);
|
||||||
vm.availableVaps = taxedVaps;
|
vm.availableVaps = pricedAvailableVaps;
|
||||||
vm.lineItems = lineItems;
|
vm.lineItems = lineItemsForCart;
|
||||||
vm.inactivePromos = removeCurrentlyActivePromoCodesFromInactivePromos(
|
vm.inactivePromos = removeCurrentlyActivePromoCodesFromInactivePromos(
|
||||||
vm.lineItems.promos,
|
vm.lineItems.promos,
|
||||||
vm.inactivePromos
|
vm.inactivePromos
|
||||||
|
|
@ -856,7 +812,6 @@ export default {
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldValue.promos.length < newValue.promos.length) {
|
if (oldValue.promos.length < newValue.promos.length) {
|
||||||
const oldPromoCodes = oldValue.promos.map(
|
const oldPromoCodes = oldValue.promos.map(
|
||||||
(promoObject) => promoObject.promoCode
|
(promoObject) => promoObject.promoCode
|
||||||
|
|
|
||||||
|
|
@ -2958,8 +2958,14 @@ export const actions = {
|
||||||
pageNameToLog,
|
pageNameToLog,
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
const arrayOfLineItems = [
|
||||||
|
...pricedLineItems.glassParts ?? [],
|
||||||
|
...pricedLineItems.promos,
|
||||||
|
...pricedLineItems.supportingItems,
|
||||||
|
...pricedLineItems.vaps
|
||||||
|
]
|
||||||
const flattenedLineItemsWithChildParts =
|
const flattenedLineItemsWithChildParts =
|
||||||
getFlattenedArrayOfLineItemsWithChildParts(pricedLineItems);
|
getFlattenedArrayOfLineItemsWithChildParts(arrayOfLineItems);
|
||||||
|
|
||||||
const lineItemsWithOnlyPriceInfo = flattenedLineItemsWithChildParts.map((lineItem) => ({
|
const lineItemsWithOnlyPriceInfo = flattenedLineItemsWithChildParts.map((lineItem) => ({
|
||||||
partNumber: lineItem.partNumber,
|
partNumber: lineItem.partNumber,
|
||||||
|
|
@ -3008,8 +3014,9 @@ export const actions = {
|
||||||
});
|
});
|
||||||
|
|
||||||
context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData);
|
context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData);
|
||||||
|
Object.keys(pricedLineItems).forEach((key) => {
|
||||||
pricedLineItems = addTaxesToPricedLineItems(pricedLineItems, response.data.taxedLineItems);
|
pricedLineItems[key] = addTaxesToPricedLineItems(pricedLineItems[key] ?? [], response.data.taxedLineItems);
|
||||||
|
});
|
||||||
|
|
||||||
return pricedLineItems;
|
return pricedLineItems;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue