Merge pull request #1663 from Safelite/feature/CSR-1851-merge-to-release-branch
Merge pull request #1644 from Safelite/feature/CSR-1851-promo-added-w…
This commit is contained in:
commit
dc91998d6a
3 changed files with 53 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",
|
||||||
|
|
||||||
|
|
@ -272,6 +274,7 @@ 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.
|
||||||
this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems);
|
this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems);
|
||||||
|
|
@ -285,6 +288,7 @@ export default {
|
||||||
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();
|
||||||
|
|
|
||||||
|
|
@ -2626,7 +2626,7 @@ function convertGlassPieceNamingFromApi(glassArray) {
|
||||||
|
|
||||||
function addPricesToLineItems(lineItems, pricingLineItems) {
|
function addPricesToLineItems(lineItems, pricingLineItems) {
|
||||||
lineItems.forEach((lineItem) => {
|
lineItems.forEach((lineItem) => {
|
||||||
let lineItemIndex = pricingLineItems.findIndex(
|
const lineItemIndex = pricingLineItems.findIndex(
|
||||||
(pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber
|
(pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -2634,7 +2634,7 @@ function addPricesToLineItems(lineItems, pricingLineItems) {
|
||||||
addPricesToLineItems(lineItem.childParts, pricingLineItems);
|
addPricesToLineItems(lineItem.childParts, pricingLineItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
let pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0];
|
const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0];
|
||||||
lineItem.laborAmount = pricedLineItem.laborAmount;
|
lineItem.laborAmount = pricedLineItem.laborAmount;
|
||||||
lineItem.sellingPrice = pricedLineItem.sellingPrice;
|
lineItem.sellingPrice = pricedLineItem.sellingPrice;
|
||||||
lineItem.kitPrice = pricedLineItem.kitPrice;
|
lineItem.kitPrice = pricedLineItem.kitPrice;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue