CSR-1462 line items refactor fix for payment page
This commit is contained in:
parent
caac3f4887
commit
d781b7fdad
1 changed files with 34 additions and 19 deletions
|
|
@ -192,9 +192,11 @@ import { mapTaxedLineItemsToStoreFormat } from "../../store";
|
||||||
import {
|
import {
|
||||||
revalidatePromosAndValidateNewPromo,
|
revalidatePromosAndValidateNewPromo,
|
||||||
getAddableVapsFromAvailableLineItems,
|
getAddableVapsFromAvailableLineItems,
|
||||||
|
getVapsThatNeedToBeAddedToSatisfyPromos,
|
||||||
} from "@/helpers/promotions-helper";
|
} from "@/helpers/promotions-helper";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||||
|
import { deepClone } from "@/helpers/object-helper";
|
||||||
|
|
||||||
import iframeResize from "../../../node_modules/iframe-resizer/js/iframeResizer.js";
|
import iframeResize from "../../../node_modules/iframe-resizer/js/iframeResizer.js";
|
||||||
|
|
||||||
|
|
@ -228,7 +230,7 @@ export default {
|
||||||
piaLineItems: this.getPiaLineItems(),
|
piaLineItems: this.getPiaLineItems(),
|
||||||
paypalPayment: this.isPaypal(),
|
paypalPayment: this.isPaypal(),
|
||||||
lineItems: [],
|
lineItems: [],
|
||||||
availableLineItems: [],
|
availableVaps: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
directives: {
|
directives: {
|
||||||
|
|
@ -297,22 +299,22 @@ export default {
|
||||||
];
|
];
|
||||||
|
|
||||||
const resultMap = await settleAllPromises(promiseResultMap);
|
const resultMap = await settleAllPromises(promiseResultMap);
|
||||||
|
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
|
||||||
|
const glassParts = lineItemsFromStore.glassParts ?? [];
|
||||||
|
const supportingItems = lineItemsFromStore.supportingItems ?? [];
|
||||||
|
|
||||||
const glassParts = store.getters.order.lineItems.glassParts ?? [];
|
const lineItemsToTax = [
|
||||||
|
|
||||||
let availableLineItems = [
|
|
||||||
resultMap.rainDefense,
|
resultMap.rainDefense,
|
||||||
...resultMap.supportingItems,
|
...supportingItems,
|
||||||
...resultMap.wipers,
|
...resultMap.wipers,
|
||||||
...glassParts,
|
...glassParts,
|
||||||
];
|
];
|
||||||
|
const availableVaps = [resultMap.rainDefense, ...resultMap.wipers];
|
||||||
|
|
||||||
const lineItemsFromStore = store.getters.order.lineItems;
|
const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
|
|
||||||
await baseMixin.methods.dispatchStoreActionWithLogging(
|
|
||||||
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||||
{
|
{
|
||||||
availableLineItems: availableLineItems,
|
availableLineItems: lineItemsToTax,
|
||||||
},
|
},
|
||||||
"payment",
|
"payment",
|
||||||
false
|
false
|
||||||
|
|
@ -324,14 +326,16 @@ export default {
|
||||||
const { validatePromoResponse, revalidatePromoResponse } =
|
const { validatePromoResponse, revalidatePromoResponse } =
|
||||||
await revalidatePromosAndValidateNewPromo(
|
await revalidatePromosAndValidateNewPromo(
|
||||||
promoCodeFromQueryString,
|
promoCodeFromQueryString,
|
||||||
availableLineItems,
|
pricedLineItemsToTax,
|
||||||
"payment-method"
|
"payment"
|
||||||
);
|
);
|
||||||
|
|
||||||
availableLineItems.push(...(validatePromoResponse?.orderPromos ?? []));
|
const newValidatedPromos = validatePromoResponse?.orderPromos ?? [];
|
||||||
|
|
||||||
|
pricedLineItemsToTax.push(...newValidatedPromos);
|
||||||
// End of promo logic
|
// End of promo logic
|
||||||
|
|
||||||
const taxedAvailableLineItems = await baseMixin.methods.dispatchStoreActionWithLogging(
|
const taxedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||||
{
|
{
|
||||||
billToAccountNumber: "87291",
|
billToAccountNumber: "87291",
|
||||||
|
|
@ -340,22 +344,33 @@ 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,
|
||||||
pricedAvailableLineItems: availableLineItems,
|
pricedLineItems: pricedLineItemsToTax,
|
||||||
},
|
},
|
||||||
"payment-method",
|
"payment",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Match all available 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.
|
||||||
const lineItems = mapTaxedLineItemsToStoreFormat(availableLineItems, lineItemsFromStore);
|
const lineItems = mapTaxedLineItemsToStoreFormat(taxedLineItems, lineItemsFromStore);
|
||||||
|
const taxedVaps = mapTaxedLineItemsToStoreFormat(taxedLineItems, availableVaps);
|
||||||
|
|
||||||
|
// Add items that were not in the store yet but added via query string promo validation
|
||||||
|
lineItems.promos = lineItems.promos ?? [];
|
||||||
|
lineItems.promos.push(...newValidatedPromos);
|
||||||
|
const vapsToAddToCart = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||||
|
newValidatedPromos,
|
||||||
|
taxedVaps,
|
||||||
|
lineItems
|
||||||
|
);
|
||||||
|
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(async (vm) => {
|
next(async (vm) => {
|
||||||
vm.setCmsContent(resultMap.cmsContent);
|
vm.setCmsContent(resultMap.cmsContent);
|
||||||
vm.fetchSignatureInfo(resultMap.signature);
|
vm.fetchSignatureInfo(resultMap.signature);
|
||||||
|
|
||||||
vm.availableLineItems = taxedAvailableLineItems;
|
vm.availableVaps = taxedVaps;
|
||||||
vm.lineItems = lineItems;
|
vm.lineItems = lineItems;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue