Merge pull request #1644 from Safelite/feature/CSR-1851-promo-added-wipers-redux

Feature/csr 1851 promo added wipers redux
This commit is contained in:
Leah Schumann 2023-12-19 09:47:29 -05:00 committed by GitHub
commit edd05d1864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 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",
@ -272,6 +274,7 @@ export default {
"payment-method",
false
);
// Match all line items to the line items as they are in the store
// and rebuild the original structure.
this.lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, this.lineItems);
@ -285,6 +288,7 @@ export default {
taxedVaps,
this.lineItems
);
this.lineItems?.promos.push(...promoCodeData.promoCode);
this.lineItems.vaps?.push(...getVaps);
this.closeModal();

View file

@ -2641,7 +2641,7 @@ function convertGlassPieceNamingFromApi(glassArray) {
function addPricesToLineItems(lineItems, pricingLineItems) {
lineItems.forEach((lineItem) => {
let lineItemIndex = pricingLineItems.findIndex(
const lineItemIndex = pricingLineItems.findIndex(
(pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber
);
@ -2649,7 +2649,7 @@ function addPricesToLineItems(lineItems, pricingLineItems) {
addPricesToLineItems(lineItem.childParts, pricingLineItems);
}
let pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0];
const pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0];
lineItem.laborAmount = pricedLineItem.laborAmount;
lineItem.sellingPrice = pricedLineItem.sellingPrice;
lineItem.kitPrice = pricedLineItem.kitPrice;