Merge pull request #1515 from Safelite/feature/CSR-1393.1

Feature/csr 1393.1
This commit is contained in:
AMSNEHA 2023-11-13 20:20:02 +05:30 committed by GitHub
commit 74eaa773c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 64 deletions

View file

@ -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",

View file

@ -34,7 +34,6 @@
class="pb-3"
v-model="lineItems"
:availableVaps="availableVaps"
@added-to-cart="showAlert"
linkWidgetName="PromoLinkWidget"
modalWidgetName="PromoModalWidget" />

View file

@ -9,6 +9,7 @@
<modal
:ref="modalName"
:headerText="modalHeaderText"
:onModalClosedCallback="onModalClosed"
:footerButtonText="modalFooterText"
@footer-button-event="addPromoCode">
<promoQuestion
@ -24,6 +25,14 @@
cmsWidgetName="AlertInvalidPromoWidget"
alertClass="alert-danger"
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">
<span class="applied-promo">Promo code "{{ promo.promoCode }}" applied </span>
<textLink
@ -42,7 +51,10 @@ import promoQuestion from "@/layouts/payment-method/promo-modal-question/promo-q
import modal from "@/digital-components/modal/modal";
import alert from "@/ux-components/alert/alert";
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 baseMixin from "@/mixins/base-mixin.js";
import { cartItemCategories } from "@/constants/cart-item-categories";
@ -97,9 +109,6 @@ export default {
InvalidPromoText() {
return this.PromoText?.replaceAll("{custom:PROMOCODE}", this.promoCode);
},
AddPromoSuccessMessageFromCms() {
return this.getCmsContent("PromoSuccessAlertWidget", "Text");
},
removeLinkText() {
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
},
@ -120,6 +129,9 @@ export default {
closeModal() {
this.modal.closeModal();
},
onModalClosed() {
this.$emit("update:modelValue", this.lineItems);
},
focusOnPromoInput() {
const input = document.getElementById(this.promoTextInputId);
input?.focus();
@ -155,16 +167,14 @@ export default {
};
},
removeItem(promo) {
//let lineItems = this.modelValue;
this.lineItems[cartItemCategories.PROMOS] = this.lineItems[
cartItemCategories.PROMOS
].filter((lineItemsToKeep) => 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) {