Changed to use wipers already on the order as available wipers so that if the zip changes it doesn't matter

This commit is contained in:
Leah Schumann 2023-12-18 06:50:48 -05:00
parent 1d7dc6c2c9
commit 2bcf9785e7
2 changed files with 54 additions and 32 deletions

View file

@ -123,14 +123,28 @@ export default {
// Call APIs
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.GET_WIPERS,
{
serviceZipCode: store.getters.order.serviceLocation.zipCode,
carId: store.getters.vehicle.carId,
},
"payment-method"
);
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
const frontWipersOnOrder =
lineItemsFromStore.vaps.filter(
(wiper) => wiper.partType == partTypeStrings.FRONT_WIPER
) ?? [];
const rearWipersOnOrder =
lineItemsFromStore.vaps.filter(
(wiper) => wiper.partType == partTypeStrings.REAR_WIPER
) ?? [];
const orderHasFrontWipers = frontWipersOnOrder.length > 0;
const orderHasRearWipers = rearWipersOnOrder.length > 0;
const wipersPromise = orderHasFrontWipers
? 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(
storeActions.GET_RAIN_DEFENSE,
@ -154,19 +168,36 @@ export default {
];
const resultMap = await settleAllPromises(promiseResultMap);
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
const glassParts = lineItemsFromStore.glassParts ?? [];
const supportingItems = lineItemsFromStore.supportingItems ?? [];
const vaps = lineItemsFromStore.vaps ?? [];
// if the order already has wipers on it from the quote page, use those as the available 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 lineItemsToTax = [
resultMap.rainDefense,
...supportingItems,
...resultMap.wipers,
...availableFrontWipers,
...availableRearWipers,
...glassParts,
...vaps,
];
const availableVaps = [resultMap.rainDefense, ...resultMap.wipers];
const availableVaps = [
resultMap.rainDefense,
...availableFrontWipers,
...availableRearWipers,
];
const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
@ -381,36 +412,19 @@ export default {
);
}
// Because we don't yet have a robust solution for part interchange ...
// if there are front wiper line items in the revalidate response, we need to delete any existing front wiper line items from the store
// and replace them with those that come back from revalidation.
const revalidateResponseHasFrontWiperLineItems =
revalidatePromoResponse.promoLineItems.find(
(lineItem) => lineItem.partType == partTypeStrings.FRONT_WIPER
).length > 0;
if (revalidateResponseHasFrontWiperLineItems) {
const frontWiperLineItemsInStore = this.lineItems.vaps.find(
(lineItem) => lineItem.partType == partTypeStrings.FRONT_WIPER
);
if (frontWiperLineItemsInStore.length > 0) {
this.lineItems.vaps = this.lineItems.vaps.find(
(lineItem) => lineItem.partType != partTypeStrings.FRONT_WIPER
);
}
}
const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos(
revalidatePromoResponse.promoLineItems,
this.availableVaps,
this.lineItems
);
this.lineItems.vaps.push(...vapsToAddToCart);
this.lineItems.promos = revalidatePromoResponse.promoLineItems;
this.inactivePromos = revalidatePromoResponse.errors.map((x) =>
getPromoCodeWithoutBundleIdentifier(x.promoCode)
);
this.$refs.loadingModal.hideModal();
},
backButtonAction() {
@ -547,13 +561,16 @@ export default {
) {
return;
}
if (oldValue.promos.length < newValue.promos.length) {
const oldPromoCodes = oldValue.promos.map(
(promoObject) => promoObject.promoCode
);
const newlyActivatedPromoCodes = newValue.promos.filter(
(newPromo) => !oldPromoCodes.includes(newPromo.promoCode)
);
const alert = createPromoSuccessAlert(newlyActivatedPromoCodes[0].promoCode);
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
} else if (

View file

@ -79,6 +79,8 @@ import baseMixin from "@/mixins/base-mixin.js";
import { cartItemCategories } from "@/constants/cart-item-categories";
import store from "@/store";
import { mapTaxedLineItemsToStoreFormat } from "@/store";
import { partTypeStrings } from "@/constants/part-type-strings";
export default {
name: "promo-modal-question",
@ -253,7 +255,7 @@ export default {
this.availableVaps,
"payment-method"
);
console.log(promoCodeData);
if (promoCodeData.isValid) {
const pricedLineItemsToTax = [];
pricedLineItemsToTax.push(...promoCodeData.promoCode);
@ -272,19 +274,22 @@ export default {
"payment-method",
false
);
// Match all line items to the line items as they are in the store
// and rebuild the original structure.
console.log(this.lineItems.vaps);
this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems);
const taxedVaps = mapTaxedLineItemsToStoreFormat(
taxedLineItems,
this.availableVaps
);
console.log(this.lineItems.vaps);
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
promoCodeData.promoCode,
taxedVaps,
this.lineItems
);
this.lineItems?.promos.push(...promoCodeData.promoCode);
this.lineItems.vaps?.push(...getVaps);
this.closeModal();