diff --git a/src/helpers/promotions-helper.js b/src/helpers/promotions-helper.js index d18a4aa17..996ca1aa6 100644 --- a/src/helpers/promotions-helper.js +++ b/src/helpers/promotions-helper.js @@ -16,7 +16,7 @@ export const addableVapsPromoPartNumbers = [ promoPartNumberStrings.WIPER_DISCOUNT_PART_NUMBER, ]; -const promoErrorCodes = { +export const promoErrorCodes = { UNKNOWN: "Unknown", PROMO_NOT_YET_IN_USE: "PromoNotYetInUse", PROMO_USAGE_COUNT_EXCEEDED: "PromoUsageCountExceeded", diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index 0d6f338bb..d672dbd06 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -34,7 +34,6 @@ class="pb-3" v-model="lineItems" :availableVaps="availableVaps" - @added-to-cart="showAlert" linkWidgetName="PromoLinkWidget" modalWidgetName="PromoModalWidget" /> diff --git a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue index 91388396b..db04dfb00 100644 --- a/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue +++ b/src/layouts/payment-method/promo-modal-question/promo-modal-question.vue @@ -9,6 +9,7 @@ +
Promo code "{{ promo.promoCode }}" applied lineItemsToKeep.promoCode != promo); - - this.$emit("update:modelValue", this.lineItems); }, async addPromoCode() { if (this.promoCode) { this.resetAlerts(); + const promoCodeData = await this.getPromoCodeData( this.promoCode, this.lineItems, @@ -173,65 +183,46 @@ export default { ); if (promoCodeData.isValid) { - const addedPromo = this.lineItems?.promos.find( - (promoItem) => - promoItem?.promoCode == promoCodeData.promoCode?.[0]?.promoCode + const pricedLineItemsToTax = []; + pricedLineItemsToTax.push(...promoCodeData.promoCode); + const taxedLineItems = await baseMixin.methods.dispatchStoreActionWithLogging( + storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA, + { + billToAccountNumber: "87291", + 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 ); - if (addedPromo) { - this.displayInvalidPromoAlert = true; + // 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.availableVaps + ); + + const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos( + promoCodeData.promoCode, + taxedVaps, + this.lineItems + ); + this.lineItems?.promos.push(...promoCodeData.promoCode); + this.lineItems.vaps?.push(...getVaps); + this.closeModal(); + this.promoCode = ""; + } else { + if (promoCodeData.errorCode == promoErrorCodes.PROMO_STACKING_NOT_ALLOWED) { + this.displayInvalidPromoOnOrderAlert = true; this.focusOnPromoInput(); this.resetModalButtonStyle(); - } else { - const pricedLineItemsToTax = []; - pricedLineItemsToTax.push(...promoCodeData.promoCode); - const taxedLineItems = - await baseMixin.methods.dispatchStoreActionWithLogging( - storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA, - { - billToAccountNumber: "87291", - 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 - ); - // 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.availableVaps - ); - - const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos( - promoCodeData.promoCode, - taxedVaps, - this.lineItems - ); - this.lineItems?.promos.push(...promoCodeData.promoCode); - this.lineItems.vaps?.push(...getVaps); - this.closeModal(); - const message = this.getPromoAddedMessage(); - this.$emit("update:modelValue", this.lineItems); - this.$emit("added-to-cart", { - messageHeadline: "Promo Applied!", - messageCopy: message, - type: "alert-success", - isDismissible: true, - }); - this.promoCode = ""; } - } else { this.displayInvalidPromoAlert = true; this.focusOnPromoInput(); this.resetModalButtonStyle(); @@ -242,6 +233,7 @@ export default { watch: { promoCode() { this.displayInvalidPromoAlert = false; + this.displayInvalidOnOrderPromoAlert = false; }, modelValue: { handler(newValue) {