Merge pull request #1515 from Safelite/feature/CSR-1393.1
Feature/csr 1393.1
This commit is contained in:
commit
74eaa773c0
3 changed files with 55 additions and 64 deletions
|
|
@ -16,7 +16,7 @@ export const addableVapsPromoPartNumbers = [
|
||||||
promoPartNumberStrings.WIPER_DISCOUNT_PART_NUMBER,
|
promoPartNumberStrings.WIPER_DISCOUNT_PART_NUMBER,
|
||||||
];
|
];
|
||||||
|
|
||||||
const promoErrorCodes = {
|
export const promoErrorCodes = {
|
||||||
UNKNOWN: "Unknown",
|
UNKNOWN: "Unknown",
|
||||||
PROMO_NOT_YET_IN_USE: "PromoNotYetInUse",
|
PROMO_NOT_YET_IN_USE: "PromoNotYetInUse",
|
||||||
PROMO_USAGE_COUNT_EXCEEDED: "PromoUsageCountExceeded",
|
PROMO_USAGE_COUNT_EXCEEDED: "PromoUsageCountExceeded",
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@
|
||||||
class="pb-3"
|
class="pb-3"
|
||||||
v-model="lineItems"
|
v-model="lineItems"
|
||||||
:availableVaps="availableVaps"
|
:availableVaps="availableVaps"
|
||||||
@added-to-cart="showAlert"
|
|
||||||
linkWidgetName="PromoLinkWidget"
|
linkWidgetName="PromoLinkWidget"
|
||||||
modalWidgetName="PromoModalWidget" />
|
modalWidgetName="PromoModalWidget" />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<modal
|
<modal
|
||||||
:ref="modalName"
|
:ref="modalName"
|
||||||
:headerText="modalHeaderText"
|
:headerText="modalHeaderText"
|
||||||
|
:onModalClosedCallback="onModalClosed"
|
||||||
:footerButtonText="modalFooterText"
|
:footerButtonText="modalFooterText"
|
||||||
@footer-button-event="addPromoCode">
|
@footer-button-event="addPromoCode">
|
||||||
<promoQuestion
|
<promoQuestion
|
||||||
|
|
@ -24,6 +25,14 @@
|
||||||
cmsWidgetName="AlertInvalidPromoWidget"
|
cmsWidgetName="AlertInvalidPromoWidget"
|
||||||
alertClass="alert-danger"
|
alertClass="alert-danger"
|
||||||
v-bind:isDismissible="true" />
|
v-bind:isDismissible="true" />
|
||||||
|
<alert
|
||||||
|
ref="alertInvalidPromoOnOrder"
|
||||||
|
v-if="displayInvalidOnOrderPromoAlert"
|
||||||
|
v-html="InvalidPromoOnOrderText"
|
||||||
|
class="my-4 alert"
|
||||||
|
cmsWidgetName="AlertInvalidPromoOnOrderWidget"
|
||||||
|
alertClass="alert-danger"
|
||||||
|
v-bind:isDismissible="true" />
|
||||||
<div v-for="(promo, i) in this.getPromoList()" :key="i">
|
<div v-for="(promo, i) in this.getPromoList()" :key="i">
|
||||||
<span class="applied-promo">Promo code "{{ promo.promoCode }}" applied </span>
|
<span class="applied-promo">Promo code "{{ promo.promoCode }}" applied </span>
|
||||||
<textLink
|
<textLink
|
||||||
|
|
@ -42,7 +51,10 @@ import promoQuestion from "@/layouts/payment-method/promo-modal-question/promo-q
|
||||||
import modal from "@/digital-components/modal/modal";
|
import modal from "@/digital-components/modal/modal";
|
||||||
import alert from "@/ux-components/alert/alert";
|
import alert from "@/ux-components/alert/alert";
|
||||||
import { storeActions } from "@/constants/store-actions.js";
|
import { storeActions } from "@/constants/store-actions.js";
|
||||||
import { getVapsThatNeedToBeAddedToSatisfyPromos } from "@/helpers/promotions-helper";
|
import {
|
||||||
|
getVapsThatNeedToBeAddedToSatisfyPromos,
|
||||||
|
promoErrorCodes,
|
||||||
|
} from "@/helpers/promotions-helper";
|
||||||
import { deepClone } from "@/helpers/object-helper";
|
import { deepClone } from "@/helpers/object-helper";
|
||||||
import baseMixin from "@/mixins/base-mixin.js";
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
import { cartItemCategories } from "@/constants/cart-item-categories";
|
import { cartItemCategories } from "@/constants/cart-item-categories";
|
||||||
|
|
@ -97,9 +109,6 @@ export default {
|
||||||
InvalidPromoText() {
|
InvalidPromoText() {
|
||||||
return this.PromoText?.replaceAll("{custom:PROMOCODE}", this.promoCode);
|
return this.PromoText?.replaceAll("{custom:PROMOCODE}", this.promoCode);
|
||||||
},
|
},
|
||||||
AddPromoSuccessMessageFromCms() {
|
|
||||||
return this.getCmsContent("PromoSuccessAlertWidget", "Text");
|
|
||||||
},
|
|
||||||
removeLinkText() {
|
removeLinkText() {
|
||||||
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
|
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
|
||||||
},
|
},
|
||||||
|
|
@ -120,6 +129,9 @@ export default {
|
||||||
closeModal() {
|
closeModal() {
|
||||||
this.modal.closeModal();
|
this.modal.closeModal();
|
||||||
},
|
},
|
||||||
|
onModalClosed() {
|
||||||
|
this.$emit("update:modelValue", this.lineItems);
|
||||||
|
},
|
||||||
focusOnPromoInput() {
|
focusOnPromoInput() {
|
||||||
const input = document.getElementById(this.promoTextInputId);
|
const input = document.getElementById(this.promoTextInputId);
|
||||||
input?.focus();
|
input?.focus();
|
||||||
|
|
@ -155,16 +167,14 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
removeItem(promo) {
|
removeItem(promo) {
|
||||||
//let lineItems = this.modelValue;
|
|
||||||
this.lineItems[cartItemCategories.PROMOS] = this.lineItems[
|
this.lineItems[cartItemCategories.PROMOS] = this.lineItems[
|
||||||
cartItemCategories.PROMOS
|
cartItemCategories.PROMOS
|
||||||
].filter((lineItemsToKeep) => lineItemsToKeep.promoCode != promo);
|
].filter((lineItemsToKeep) => lineItemsToKeep.promoCode != promo);
|
||||||
|
|
||||||
this.$emit("update:modelValue", this.lineItems);
|
|
||||||
},
|
},
|
||||||
async addPromoCode() {
|
async addPromoCode() {
|
||||||
if (this.promoCode) {
|
if (this.promoCode) {
|
||||||
this.resetAlerts();
|
this.resetAlerts();
|
||||||
|
|
||||||
const promoCodeData = await this.getPromoCodeData(
|
const promoCodeData = await this.getPromoCodeData(
|
||||||
this.promoCode,
|
this.promoCode,
|
||||||
this.lineItems,
|
this.lineItems,
|
||||||
|
|
@ -173,65 +183,46 @@ export default {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (promoCodeData.isValid) {
|
if (promoCodeData.isValid) {
|
||||||
const addedPromo = this.lineItems?.promos.find(
|
const pricedLineItemsToTax = [];
|
||||||
(promoItem) =>
|
pricedLineItemsToTax.push(...promoCodeData.promoCode);
|
||||||
promoItem?.promoCode == promoCodeData.promoCode?.[0]?.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) {
|
// Match all line items to the line items as they are in the store
|
||||||
this.displayInvalidPromoAlert = true;
|
// 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.focusOnPromoInput();
|
||||||
this.resetModalButtonStyle();
|
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.displayInvalidPromoAlert = true;
|
||||||
this.focusOnPromoInput();
|
this.focusOnPromoInput();
|
||||||
this.resetModalButtonStyle();
|
this.resetModalButtonStyle();
|
||||||
|
|
@ -242,6 +233,7 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
promoCode() {
|
promoCode() {
|
||||||
this.displayInvalidPromoAlert = false;
|
this.displayInvalidPromoAlert = false;
|
||||||
|
this.displayInvalidOnOrderPromoAlert = false;
|
||||||
},
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
handler(newValue) {
|
handler(newValue) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue