Make promo modal work with new changes
Got rid of a watcher in quote
This commit is contained in:
parent
9aa2a95bcc
commit
1d7a2b6181
3 changed files with 28 additions and 54 deletions
|
|
@ -290,8 +290,18 @@ export default {
|
|||
);
|
||||
if (promoCodeData.isValid) {
|
||||
if (this.taxPromos) {
|
||||
const pricedLineItemsToTax = [];
|
||||
pricedLineItemsToTax.push(...promoCodeData.promoCode); // promoCodeData.promoCode should be an array
|
||||
const vapsToAdd = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||
promoCodeData.promoCode,
|
||||
this.addableVaps,
|
||||
this.lineItems
|
||||
);
|
||||
const pricedLineItemsToTax = {
|
||||
glassParts: this.lineItems.glassParts,
|
||||
promos: promoCodeData.promoCode,
|
||||
supportingItems: this.lineItems.supportingItems,
|
||||
vaps: [...this.lineItems.vaps, ...vapsToAdd],
|
||||
};
|
||||
|
||||
const taxedLineItems =
|
||||
await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||
storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||
|
|
@ -311,28 +321,13 @@ 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
|
||||
);
|
||||
const taxedVaps = mapTaxedLineItemsToStoreFormat(
|
||||
taxedLineItems,
|
||||
this.addableVaps
|
||||
);
|
||||
|
||||
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||
promoCodeData.promoCode,
|
||||
taxedVaps,
|
||||
this.lineItems
|
||||
);
|
||||
|
||||
this.lineItems.vaps?.push(...getVaps);
|
||||
this.lineItems = taxedLineItems;
|
||||
} else {
|
||||
this.lineItems?.promos.push(...promoCodeData.promoCode);
|
||||
}
|
||||
this.lineItems?.promos.push(...promoCodeData.promoCode);
|
||||
|
||||
this.$emit("promoAdded", this.lineItems);
|
||||
|
||||
this.closeModal();
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@
|
|||
pageName="quote"
|
||||
:taxPromos="false"
|
||||
:useDefaultCashParentAccount="true"
|
||||
@promoAdded="promoAdded"
|
||||
modalWidgetName="PromoModalWidget" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -573,9 +574,6 @@ export default {
|
|||
isInsuranceContinueButtonText() {
|
||||
return this.getCmsContent("isInsuranceContinueButtonText", "Text");
|
||||
},
|
||||
lineItemsCloneForWatcher() {
|
||||
return Object.assign({}, this.lineItems);
|
||||
},
|
||||
isRecalibrationOnOrder() {
|
||||
return store.getters.isRecalibrationOnOrder;
|
||||
},
|
||||
|
|
@ -851,32 +849,10 @@ export default {
|
|||
await this.forwardButtonAction();
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
lineItemsCloneForWatcher: {
|
||||
handler(newValue, oldValue) {
|
||||
if (
|
||||
!oldValue ||
|
||||
oldValue.length == 0 ||
|
||||
!oldValue.vaps ||
|
||||
!newValue ||
|
||||
newValue.length == 0
|
||||
) {
|
||||
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);
|
||||
}
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
promoAdded(lineItems) {
|
||||
const alert = createPromoSuccessAlert(lineItems.promos[0].promoCode);
|
||||
this.$refs.funnelHeader.pushGlobalAlert(alert, alert.shouldAutoFade);
|
||||
}
|
||||
},
|
||||
components: {
|
||||
funnelHeader,
|
||||
|
|
|
|||
|
|
@ -2959,11 +2959,11 @@ export const actions = {
|
|||
}
|
||||
) {
|
||||
const arrayOfLineItems = [
|
||||
...pricedLineItems.glassParts ?? [],
|
||||
...(pricedLineItems.glassParts ?? []),
|
||||
...pricedLineItems.promos,
|
||||
...pricedLineItems.supportingItems,
|
||||
...pricedLineItems.vaps
|
||||
]
|
||||
...pricedLineItems.vaps,
|
||||
];
|
||||
const flattenedLineItemsWithChildParts =
|
||||
getFlattenedArrayOfLineItemsWithChildParts(arrayOfLineItems);
|
||||
|
||||
|
|
@ -3015,7 +3015,10 @@ export const actions = {
|
|||
|
||||
context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData);
|
||||
Object.keys(pricedLineItems).forEach((key) => {
|
||||
pricedLineItems[key] = addTaxesToPricedLineItems(pricedLineItems[key] ?? [], response.data.taxedLineItems);
|
||||
pricedLineItems[key] = addTaxesToPricedLineItems(
|
||||
pricedLineItems[key] ?? [],
|
||||
response.data.taxedLineItems
|
||||
);
|
||||
});
|
||||
|
||||
return pricedLineItems;
|
||||
|
|
|
|||
Loading…
Reference in a new issue