taxable promo
taxable promo and lineitems
This commit is contained in:
parent
5fda20d9ab
commit
ab507a9280
3 changed files with 66 additions and 29 deletions
|
|
@ -230,6 +230,7 @@ export default {
|
||||||
(promoLineItem?.laborAmount ?? 0) +
|
(promoLineItem?.laborAmount ?? 0) +
|
||||||
(promoLineItem?.sellingPrice ?? 0),
|
(promoLineItem?.sellingPrice ?? 0),
|
||||||
salesTax: promoLineItem?.salesTax,
|
salesTax: promoLineItem?.salesTax,
|
||||||
|
lineItems:[],
|
||||||
};
|
};
|
||||||
|
|
||||||
promoLineItem.cartItemType = cartItem.cartItemType;
|
promoLineItem.cartItemType = cartItem.cartItemType;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
<promoModalQuestion
|
<promoModalQuestion
|
||||||
class="pb-3"
|
class="pb-3"
|
||||||
v-model="lineItems"
|
v-model="lineItems"
|
||||||
:availableLineItems="availableLineItems"
|
:availableVaps="availableVaps"
|
||||||
@added-to-cart="showAlert"
|
@added-to-cart="showAlert"
|
||||||
linkWidgetName="PromoLinkWidget"
|
linkWidgetName="PromoLinkWidget"
|
||||||
modalWidgetName="PromoModalWidget" />
|
modalWidgetName="PromoModalWidget" />
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ 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 {
|
import { getVapsThatNeedToBeAddedToSatisfyPromos } from "@/helpers/promotions-helper";
|
||||||
getVapsThatNeedToBeAddedToSatisfyPromos,
|
import { deepClone } from "@/helpers/object-helper";
|
||||||
getAddableVapsFromAvailableLineItems,
|
|
||||||
} from "@/helpers/promotions-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";
|
||||||
|
import store from "@/store";
|
||||||
|
import { mapTaxedLineItemsToStoreFormat } from "@/store";
|
||||||
export default {
|
export default {
|
||||||
name: "promo-modal-question",
|
name: "promo-modal-question",
|
||||||
|
|
||||||
|
|
@ -57,15 +57,15 @@ export default {
|
||||||
promoTextInputId: "",
|
promoTextInputId: "",
|
||||||
displayInvalidPromoAlert: false,
|
displayInvalidPromoAlert: false,
|
||||||
displayInvalidOnOrderPromoAlert: false,
|
displayInvalidOnOrderPromoAlert: false,
|
||||||
|
lineItems: deepClone(this.modelValue),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
modelValue: Object,
|
modelValue: Object,
|
||||||
linkWidgetName: String,
|
linkWidgetName: String,
|
||||||
modalWidgetName: String,
|
modalWidgetName: String,
|
||||||
availableLineItems: Object,
|
availableVaps: Object,
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
promoLinkText() {
|
promoLinkText() {
|
||||||
return this.getCmsContent(this.linkWidgetName, "BodyText");
|
return this.getCmsContent(this.linkWidgetName, "BodyText");
|
||||||
|
|
@ -112,7 +112,7 @@ export default {
|
||||||
this.resetAlerts();
|
this.resetAlerts();
|
||||||
},
|
},
|
||||||
getPromoList() {
|
getPromoList() {
|
||||||
return this.modelValue?.promos;
|
return this.lineItems.promos;
|
||||||
},
|
},
|
||||||
openModal() {
|
openModal() {
|
||||||
this.modal.openModal();
|
this.modal.openModal();
|
||||||
|
|
@ -133,16 +133,16 @@ export default {
|
||||||
this.promoCode
|
this.promoCode
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
async getPromoCodeData(promoCode, lineItems, availableLineItems, pageNameToLog = null) {
|
async getPromoCodeData(promoCode, lineItems, availableVaps, pageNameToLog = null) {
|
||||||
const pageName = pageNameToLog ?? this.$options?.name;
|
const pageName = pageNameToLog ?? this.$options?.name;
|
||||||
const addableVaps = getAddableVapsFromAvailableLineItems(availableLineItems);
|
//const addableVaps = getAddableVapsFromAvailableLineItems(availableLineItems);
|
||||||
const lineItemsToUse = lineItems.Length > 0 ? lineItems : null;
|
//const lineItemsToUse = lineItems.Length > 0 ? lineItems : null;
|
||||||
const promoValidationResponse = await baseMixin.methods.dispatchStoreActionWithLogging(
|
const promoValidationResponse = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
storeActions.VALIDATE_ORDER_PROMO_AND_SAVE_SERVER_DATA,
|
storeActions.VALIDATE_ORDER_PROMO_AND_SAVE_SERVER_DATA,
|
||||||
{
|
{
|
||||||
promoCode: promoCode,
|
promoCode: promoCode,
|
||||||
lineItemsToUse: lineItemsToUse,
|
lineItemsToUse: lineItems,
|
||||||
addableVaps: addableVaps,
|
addableVaps: availableVaps,
|
||||||
},
|
},
|
||||||
pageName,
|
pageName,
|
||||||
false
|
false
|
||||||
|
|
@ -155,27 +155,25 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
removeItem(promo) {
|
removeItem(promo) {
|
||||||
let lineItems = this.modelValue;
|
//let lineItems = this.modelValue;
|
||||||
lineItems[cartItemCategories.PROMOS] = lineItems[cartItemCategories.PROMOS].filter(
|
this.lineItems[cartItemCategories.PROMOS] = this.lineItems[
|
||||||
(lineItemsToKeep) => lineItemsToKeep.promoCode != promo
|
cartItemCategories.PROMOS
|
||||||
);
|
].filter((lineItemsToKeep) => lineItemsToKeep.promoCode != promo);
|
||||||
|
|
||||||
this.$emit("update:modelValue", lineItems);
|
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.modelValue,
|
this.lineItems,
|
||||||
this.availableLineItems,
|
this.availableVaps,
|
||||||
"payment-method"
|
"payment-method"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (promoCodeData.isValid) {
|
if (promoCodeData.isValid) {
|
||||||
const modelValue = this.modelValue;
|
const addedPromo = this.lineItems?.promos.find(
|
||||||
const addedPromo = modelValue?.promos.find(
|
|
||||||
(promoItem) =>
|
(promoItem) =>
|
||||||
promoItem?.promoCode == promoCodeData.promoCode?.[0]?.promoCode
|
promoItem?.promoCode == promoCodeData.promoCode?.[0]?.promoCode
|
||||||
);
|
);
|
||||||
|
|
@ -183,23 +181,55 @@ export default {
|
||||||
this.displayInvalidPromoAlert = true;
|
this.displayInvalidPromoAlert = true;
|
||||||
this.focusOnPromoInput();
|
this.focusOnPromoInput();
|
||||||
this.resetModalButtonStyle();
|
this.resetModalButtonStyle();
|
||||||
} else {
|
} else {
|
||||||
modelValue?.promos.push(...promoCodeData.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
|
||||||
|
);
|
||||||
|
// 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(
|
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
|
||||||
promoCodeData.promoCode,
|
promoCodeData.promoCode,
|
||||||
this.availableLineItems,
|
taxedVaps,
|
||||||
modelValue
|
this.lineItems
|
||||||
);
|
);
|
||||||
modelValue.vaps?.push(...getVaps);
|
this.lineItems?.promos.push(...promoCodeData.promoCode);
|
||||||
|
this.lineItems.vaps?.push(...getVaps);
|
||||||
this.closeModal();
|
this.closeModal();
|
||||||
const message = this.getPromoAddedMessage();
|
const message = this.getPromoAddedMessage();
|
||||||
|
this.$emit("update:modelValue", this.lineItems);
|
||||||
this.$emit("added-to-cart", {
|
this.$emit("added-to-cart", {
|
||||||
messageHeadline: "Promo Applied!",
|
messageHeadline: "Promo Applied!",
|
||||||
messageCopy: message,
|
messageCopy: message,
|
||||||
type: "alert-success",
|
type: "alert-success",
|
||||||
isDismissible: true,
|
isDismissible: true,
|
||||||
});
|
});
|
||||||
this.promoCode = "";
|
this.promoCode = "";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.displayInvalidPromoAlert = true;
|
this.displayInvalidPromoAlert = true;
|
||||||
|
|
@ -213,6 +243,12 @@ export default {
|
||||||
promoCode() {
|
promoCode() {
|
||||||
this.displayInvalidPromoAlert = false;
|
this.displayInvalidPromoAlert = false;
|
||||||
},
|
},
|
||||||
|
modelValue: {
|
||||||
|
handler(newValue) {
|
||||||
|
this.lineItems = deepClone(newValue);
|
||||||
|
},
|
||||||
|
deep: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue