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?.sellingPrice ?? 0),
|
||||
salesTax: promoLineItem?.salesTax,
|
||||
lineItems:[],
|
||||
};
|
||||
|
||||
promoLineItem.cartItemType = cartItem.cartItemType;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
<promoModalQuestion
|
||||
class="pb-3"
|
||||
v-model="lineItems"
|
||||
:availableLineItems="availableLineItems"
|
||||
:availableVaps="availableVaps"
|
||||
@added-to-cart="showAlert"
|
||||
linkWidgetName="PromoLinkWidget"
|
||||
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 alert from "@/ux-components/alert/alert";
|
||||
import { storeActions } from "@/constants/store-actions.js";
|
||||
import {
|
||||
getVapsThatNeedToBeAddedToSatisfyPromos,
|
||||
getAddableVapsFromAvailableLineItems,
|
||||
} from "@/helpers/promotions-helper";
|
||||
import { getVapsThatNeedToBeAddedToSatisfyPromos } from "@/helpers/promotions-helper";
|
||||
import { deepClone } from "@/helpers/object-helper";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
import { cartItemCategories } from "@/constants/cart-item-categories";
|
||||
import store from "@/store";
|
||||
import { mapTaxedLineItemsToStoreFormat } from "@/store";
|
||||
export default {
|
||||
name: "promo-modal-question",
|
||||
|
||||
|
|
@ -57,15 +57,15 @@ export default {
|
|||
promoTextInputId: "",
|
||||
displayInvalidPromoAlert: false,
|
||||
displayInvalidOnOrderPromoAlert: false,
|
||||
lineItems: deepClone(this.modelValue),
|
||||
};
|
||||
},
|
||||
props: {
|
||||
modelValue: Object,
|
||||
linkWidgetName: String,
|
||||
modalWidgetName: String,
|
||||
availableLineItems: Object,
|
||||
availableVaps: Object,
|
||||
},
|
||||
|
||||
computed: {
|
||||
promoLinkText() {
|
||||
return this.getCmsContent(this.linkWidgetName, "BodyText");
|
||||
|
|
@ -112,7 +112,7 @@ export default {
|
|||
this.resetAlerts();
|
||||
},
|
||||
getPromoList() {
|
||||
return this.modelValue?.promos;
|
||||
return this.lineItems.promos;
|
||||
},
|
||||
openModal() {
|
||||
this.modal.openModal();
|
||||
|
|
@ -133,16 +133,16 @@ export default {
|
|||
this.promoCode
|
||||
);
|
||||
},
|
||||
async getPromoCodeData(promoCode, lineItems, availableLineItems, pageNameToLog = null) {
|
||||
async getPromoCodeData(promoCode, lineItems, availableVaps, pageNameToLog = null) {
|
||||
const pageName = pageNameToLog ?? this.$options?.name;
|
||||
const addableVaps = getAddableVapsFromAvailableLineItems(availableLineItems);
|
||||
const lineItemsToUse = lineItems.Length > 0 ? lineItems : null;
|
||||
//const addableVaps = getAddableVapsFromAvailableLineItems(availableLineItems);
|
||||
//const lineItemsToUse = lineItems.Length > 0 ? lineItems : null;
|
||||
const promoValidationResponse = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||
storeActions.VALIDATE_ORDER_PROMO_AND_SAVE_SERVER_DATA,
|
||||
{
|
||||
promoCode: promoCode,
|
||||
lineItemsToUse: lineItemsToUse,
|
||||
addableVaps: addableVaps,
|
||||
lineItemsToUse: lineItems,
|
||||
addableVaps: availableVaps,
|
||||
},
|
||||
pageName,
|
||||
false
|
||||
|
|
@ -155,27 +155,25 @@ export default {
|
|||
};
|
||||
},
|
||||
removeItem(promo) {
|
||||
let lineItems = this.modelValue;
|
||||
lineItems[cartItemCategories.PROMOS] = lineItems[cartItemCategories.PROMOS].filter(
|
||||
(lineItemsToKeep) => lineItemsToKeep.promoCode != promo
|
||||
);
|
||||
//let lineItems = this.modelValue;
|
||||
this.lineItems[cartItemCategories.PROMOS] = this.lineItems[
|
||||
cartItemCategories.PROMOS
|
||||
].filter((lineItemsToKeep) => lineItemsToKeep.promoCode != promo);
|
||||
|
||||
this.$emit("update:modelValue", lineItems);
|
||||
this.$emit("update:modelValue", this.lineItems);
|
||||
},
|
||||
async addPromoCode() {
|
||||
if (this.promoCode) {
|
||||
this.resetAlerts();
|
||||
|
||||
const promoCodeData = await this.getPromoCodeData(
|
||||
this.promoCode,
|
||||
this.modelValue,
|
||||
this.availableLineItems,
|
||||
this.lineItems,
|
||||
this.availableVaps,
|
||||
"payment-method"
|
||||
);
|
||||
|
||||
if (promoCodeData.isValid) {
|
||||
const modelValue = this.modelValue;
|
||||
const addedPromo = modelValue?.promos.find(
|
||||
const addedPromo = this.lineItems?.promos.find(
|
||||
(promoItem) =>
|
||||
promoItem?.promoCode == promoCodeData.promoCode?.[0]?.promoCode
|
||||
);
|
||||
|
|
@ -183,23 +181,55 @@ export default {
|
|||
this.displayInvalidPromoAlert = true;
|
||||
this.focusOnPromoInput();
|
||||
this.resetModalButtonStyle();
|
||||
} else {
|
||||
modelValue?.promos.push(...promoCodeData.promoCode);
|
||||
} 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,
|
||||
this.availableLineItems,
|
||||
modelValue
|
||||
taxedVaps,
|
||||
this.lineItems
|
||||
);
|
||||
modelValue.vaps?.push(...getVaps);
|
||||
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 = "";
|
||||
this.promoCode = "";
|
||||
}
|
||||
} else {
|
||||
this.displayInvalidPromoAlert = true;
|
||||
|
|
@ -213,6 +243,12 @@ export default {
|
|||
promoCode() {
|
||||
this.displayInvalidPromoAlert = false;
|
||||
},
|
||||
modelValue: {
|
||||
handler(newValue) {
|
||||
this.lineItems = deepClone(newValue);
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
|
||||
components: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue