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:
parent
1d7dc6c2c9
commit
2bcf9785e7
2 changed files with 54 additions and 32 deletions
|
|
@ -123,14 +123,28 @@ export default {
|
||||||
// Call APIs
|
// Call APIs
|
||||||
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
|
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
|
||||||
|
|
||||||
const wipersPromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
||||||
storeActions.GET_WIPERS,
|
const frontWipersOnOrder =
|
||||||
{
|
lineItemsFromStore.vaps.filter(
|
||||||
serviceZipCode: store.getters.order.serviceLocation.zipCode,
|
(wiper) => wiper.partType == partTypeStrings.FRONT_WIPER
|
||||||
carId: store.getters.vehicle.carId,
|
) ?? [];
|
||||||
},
|
const rearWipersOnOrder =
|
||||||
"payment-method"
|
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(
|
const rainDefensePromise = baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.GET_RAIN_DEFENSE,
|
storeActions.GET_RAIN_DEFENSE,
|
||||||
|
|
@ -154,19 +168,36 @@ export default {
|
||||||
];
|
];
|
||||||
|
|
||||||
const resultMap = await settleAllPromises(promiseResultMap);
|
const resultMap = await settleAllPromises(promiseResultMap);
|
||||||
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
|
||||||
const glassParts = lineItemsFromStore.glassParts ?? [];
|
const glassParts = lineItemsFromStore.glassParts ?? [];
|
||||||
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
|
||||||
|
// 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 = [
|
const lineItemsToTax = [
|
||||||
resultMap.rainDefense,
|
resultMap.rainDefense,
|
||||||
...supportingItems,
|
...supportingItems,
|
||||||
...resultMap.wipers,
|
...availableFrontWipers,
|
||||||
|
...availableRearWipers,
|
||||||
...glassParts,
|
...glassParts,
|
||||||
...vaps,
|
...vaps,
|
||||||
];
|
];
|
||||||
const availableVaps = [resultMap.rainDefense, ...resultMap.wipers];
|
|
||||||
|
const availableVaps = [
|
||||||
|
resultMap.rainDefense,
|
||||||
|
...availableFrontWipers,
|
||||||
|
...availableRearWipers,
|
||||||
|
];
|
||||||
|
|
||||||
const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging(
|
const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
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(
|
const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||||
revalidatePromoResponse.promoLineItems,
|
revalidatePromoResponse.promoLineItems,
|
||||||
this.availableVaps,
|
this.availableVaps,
|
||||||
this.lineItems
|
this.lineItems
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lineItems.vaps.push(...vapsToAddToCart);
|
this.lineItems.vaps.push(...vapsToAddToCart);
|
||||||
|
|
||||||
this.lineItems.promos = revalidatePromoResponse.promoLineItems;
|
this.lineItems.promos = revalidatePromoResponse.promoLineItems;
|
||||||
this.inactivePromos = revalidatePromoResponse.errors.map((x) =>
|
this.inactivePromos = revalidatePromoResponse.errors.map((x) =>
|
||||||
getPromoCodeWithoutBundleIdentifier(x.promoCode)
|
getPromoCodeWithoutBundleIdentifier(x.promoCode)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.$refs.loadingModal.hideModal();
|
this.$refs.loadingModal.hideModal();
|
||||||
},
|
},
|
||||||
backButtonAction() {
|
backButtonAction() {
|
||||||
|
|
@ -547,13 +561,16 @@ 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
|
||||||
);
|
);
|
||||||
|
|
||||||
const newlyActivatedPromoCodes = newValue.promos.filter(
|
const newlyActivatedPromoCodes = newValue.promos.filter(
|
||||||
(newPromo) => !oldPromoCodes.includes(newPromo.promoCode)
|
(newPromo) => !oldPromoCodes.includes(newPromo.promoCode)
|
||||||
);
|
);
|
||||||
|
|
||||||
const alert = createPromoSuccessAlert(newlyActivatedPromoCodes[0].promoCode);
|
const alert = createPromoSuccessAlert(newlyActivatedPromoCodes[0].promoCode);
|
||||||
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
||||||
} else if (
|
} else if (
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,8 @@ import baseMixin from "@/mixins/base-mixin.js";
|
||||||
import { cartItemCategories } from "@/constants/cart-item-categories";
|
import { cartItemCategories } from "@/constants/cart-item-categories";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import { mapTaxedLineItemsToStoreFormat } from "@/store";
|
import { mapTaxedLineItemsToStoreFormat } from "@/store";
|
||||||
|
|
||||||
|
import { partTypeStrings } from "@/constants/part-type-strings";
|
||||||
export default {
|
export default {
|
||||||
name: "promo-modal-question",
|
name: "promo-modal-question",
|
||||||
|
|
||||||
|
|
@ -253,7 +255,7 @@ export default {
|
||||||
this.availableVaps,
|
this.availableVaps,
|
||||||
"payment-method"
|
"payment-method"
|
||||||
);
|
);
|
||||||
|
console.log(promoCodeData);
|
||||||
if (promoCodeData.isValid) {
|
if (promoCodeData.isValid) {
|
||||||
const pricedLineItemsToTax = [];
|
const pricedLineItemsToTax = [];
|
||||||
pricedLineItemsToTax.push(...promoCodeData.promoCode);
|
pricedLineItemsToTax.push(...promoCodeData.promoCode);
|
||||||
|
|
@ -272,19 +274,22 @@ export default {
|
||||||
"payment-method",
|
"payment-method",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Match all line items to the line items as they are in the store
|
// Match all line items to the line items as they are in the store
|
||||||
// and rebuild the original structure.
|
// and rebuild the original structure.
|
||||||
|
console.log(this.lineItems.vaps);
|
||||||
this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems);
|
this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems);
|
||||||
const taxedVaps = mapTaxedLineItemsToStoreFormat(
|
const taxedVaps = mapTaxedLineItemsToStoreFormat(
|
||||||
taxedLineItems,
|
taxedLineItems,
|
||||||
this.availableVaps
|
this.availableVaps
|
||||||
);
|
);
|
||||||
|
console.log(this.lineItems.vaps);
|
||||||
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
|
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||||
promoCodeData.promoCode,
|
promoCodeData.promoCode,
|
||||||
taxedVaps,
|
taxedVaps,
|
||||||
this.lineItems
|
this.lineItems
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lineItems?.promos.push(...promoCodeData.promoCode);
|
this.lineItems?.promos.push(...promoCodeData.promoCode);
|
||||||
this.lineItems.vaps?.push(...getVaps);
|
this.lineItems.vaps?.push(...getVaps);
|
||||||
this.closeModal();
|
this.closeModal();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue