CASH-1428 - Recalculate Pricing and Tax with line items from store

This commit is contained in:
Minojhini Valaiyapathi 2025-09-18 14:31:27 -04:00
parent 4b37fa81a0
commit 2bfd1f65ac

View file

@ -488,6 +488,46 @@ export default {
getInactivePromosFromStore() {
return this.$store.getters.order.payment.inactivePromos;
},
async getCalcOrderAndTaxedLineItems(lineItemsToTax) {
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
const pricedLineItemsToTax = await baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
{
availableLineItems: lineItemsToTax,
},
"payment-method",
false
);
const promoCodeFromQueryString = consumeQueryFromStash(queryStrings.PROMO);
const { validatePromoResponse, revalidatePromoResponse } =
await revalidatePromosAndValidateQueryStringPromo(
promoCodeFromQueryString,
pricedLineItemsToTax,
"payment-method"
);
const newValidatedPromos = validatePromoResponse?.orderPromos ?? [];
newValidatedPromos.push(
...(revalidatePromoResponse ? revalidatePromoResponse.promoLineItems : [])
);
pricedLineItemsToTax.push(...newValidatedPromos);
const taxedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
{
billToAccountNumber: store.getters.payment.billToAccountNumber,
providerNumber: store.getters.order.serviceLocation.provider.providerNumber,
appointmentType: store.getters.order.serviceLocation.appointmentType,
serviceLocationCity: store.getters.order.serviceLocation.city,
serviceLocationState: store.getters.order.serviceLocation.state,
serviceLocationZipCode: store.getters.order.serviceLocation.zipCode,
pricedLineItems: pricedLineItemsToTax,
},
"payment-method",
false
);
return mapTaxedLineItemsToStoreFormat(taxedLineItems, lineItemsFromStore);
},
async revalidatePromos() {
this.$refs.loadingModal.showModal();
const revalidatePromoResponse = await baseMixin.methods.dispatchStoreActionWithLogging(
@ -574,22 +614,32 @@ export default {
this.paymentMethod,
false
);
// recalulate pricing and tax with line items from store
const lineItemsFromStore = deepClone(store.getters.order.lineItems);
const lineItemsToTax = [
...(lineItemsFromStore.glassParts ?? []),
...(lineItemsFromStore.supportingItems ?? []),
...(lineItemsFromStore.vaps ?? []),
];
const taxedLineItems = await this.getCalcOrderAndTaxedLineItems(lineItemsToTax);
// save lineitems as they now have salestax added
await this.dispatchStoreAction(
storeActions.SAVE_GLASS_PARTS_SUPPRESSING_STATE_RESETTING,
this.lineItems.glassParts,
taxedLineItems.glassParts,
false
);
await this.dispatchStoreAction(
storeActions.SAVE_SUPPORTING_ITEMS_SUPPRESSING_STATE_RESETTING,
this.lineItems.supportingItems,
taxedLineItems.supportingItems,
false
);
await this.dispatchStoreAction(storeActions.SAVE_VAPS, this.lineItems.vaps, false);
await this.dispatchStoreAction(storeActions.SAVE_VAPS, taxedLineItems.vaps, false);
this.dispatchStoreAction(
storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS,
{
activePromos: this.lineItems.promos,
activePromos: taxedLineItems.promos,
inactivePromos: this.inactivePromos,
},
false