Fixed calculation issue, added promo cart items
This commit is contained in:
parent
3ed90a29c1
commit
5583070c2c
4 changed files with 92 additions and 79 deletions
|
|
@ -1,11 +1,12 @@
|
||||||
const cartItemTypes = {
|
const cartItemTypes = {
|
||||||
FRONT_WIPER: "FRONT WIPER",
|
FRONT_WIPERS: "FRONT WIPERS",
|
||||||
REAR_WIPER: "REAR WIPER",
|
REAR_WIPERS: "REAR WIPERS",
|
||||||
SUPPORTING_ITEMS: "SUPPORTING ITEMS",
|
SUPPORTING_ITEMS: "SUPPORTING ITEMS",
|
||||||
GLASS_PARTS: "GLASS PARTS",
|
GLASS_PARTS: "GLASS PARTS",
|
||||||
RAIN_DEFENSE: "RAIN DEFENSE",
|
RAIN_DEFENSE: "RAIN DEFENSE",
|
||||||
RECYCLE_FEE: "RECYCLE FEE",
|
RECYCLE_FEE: "RECYCLE FEE",
|
||||||
MOBILE_FEE: "MOBILE FEE",
|
MOBILE_FEE: "MOBILE FEE",
|
||||||
|
PROMOS: "PROMOS",
|
||||||
};
|
};
|
||||||
|
|
||||||
export { cartItemTypes };
|
export { cartItemTypes };
|
||||||
|
|
|
||||||
|
|
@ -129,11 +129,9 @@ export default {
|
||||||
|
|
||||||
let vapsCartItemsForSelectedPackage = [];
|
let vapsCartItemsForSelectedPackage = [];
|
||||||
|
|
||||||
console.log(this.cartItems);
|
|
||||||
console.log(packageContentTypes);
|
|
||||||
this.cartItems.forEach((cartItem) => {
|
this.cartItems.forEach((cartItem) => {
|
||||||
packageContentTypes.forEach((vapType) => {
|
packageContentTypes.forEach((vapType) => {
|
||||||
if (vapType == cartItem.cartItemType) {
|
if (cartItem.cartItemType.includes(vapType)) {
|
||||||
vapsCartItemsForSelectedPackage.push(cartItem);
|
vapsCartItemsForSelectedPackage.push(cartItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -153,17 +151,10 @@ export default {
|
||||||
return vapsTypeName.Text;
|
return vapsTypeName.Text;
|
||||||
},
|
},
|
||||||
removeItem(cartItemType, category) {
|
removeItem(cartItemType, category) {
|
||||||
console.log(
|
|
||||||
this.lineItems[category].filter(
|
|
||||||
(lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType
|
|
||||||
)
|
|
||||||
);
|
|
||||||
this.lineItems[category] = this.lineItems[category].filter(
|
this.lineItems[category] = this.lineItems[category].filter(
|
||||||
(lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType
|
(lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType
|
||||||
);
|
);
|
||||||
|
|
||||||
//console.log(`lineItemToDelete: ${lineItemIdToDelete}`)
|
|
||||||
|
|
||||||
this.$emit("update:modelValue", this.lineItems);
|
this.$emit("update:modelValue", this.lineItems);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -188,8 +179,8 @@ export default {
|
||||||
cartItems.push(this.glassPartsCartItem);
|
cartItems.push(this.glassPartsCartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.supportingItemsCartItem) {
|
if (this.otherSupportingItemsCartItem) {
|
||||||
cartItems.push(this.supportingItemsCartItem);
|
cartItems.push(this.otherSupportingItemsCartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.recycleFeeCartItem) {
|
if (this.recycleFeeCartItem) {
|
||||||
|
|
@ -200,6 +191,25 @@ export default {
|
||||||
cartItems.push(this.mobileFeeCartItem);
|
cartItems.push(this.mobileFeeCartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a cart item for each promo
|
||||||
|
this.promos.forEach((promoLineItem) => {
|
||||||
|
let cartItem = null;
|
||||||
|
|
||||||
|
cartItem = {
|
||||||
|
name: "Some Kind of Promo", // get from CMS?
|
||||||
|
category: cartItemCategories.PROMOS,
|
||||||
|
cartItemType: promoLineItem.partType,
|
||||||
|
isDisplayed: true,
|
||||||
|
subTotal:
|
||||||
|
(promoLineItem.kitPrice ?? 0) +
|
||||||
|
(promoLineItem.laborAmount ?? 0) +
|
||||||
|
(promoLineItem.sellingPrice ?? 0),
|
||||||
|
salesTax: promoLineItem.salesTax,
|
||||||
|
};
|
||||||
|
|
||||||
|
cartItems.push(cartItem);
|
||||||
|
});
|
||||||
|
|
||||||
return cartItems;
|
return cartItems;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -262,6 +272,10 @@ export default {
|
||||||
const supportingItems = this.lineItems?.supportingItems;
|
const supportingItems = this.lineItems?.supportingItems;
|
||||||
return supportingItems?.length > 0 ? supportingItems : [];
|
return supportingItems?.length > 0 ? supportingItems : [];
|
||||||
},
|
},
|
||||||
|
promos() {
|
||||||
|
const promos = this.lineItems?.promos;
|
||||||
|
return promos?.length > 0 ? promos : [];
|
||||||
|
},
|
||||||
// Cart Items
|
// Cart Items
|
||||||
packageCartItems() {
|
packageCartItems() {
|
||||||
return this.getVapsCartItemsForSelectedPackage(this.packageLevel);
|
return this.getVapsCartItemsForSelectedPackage(this.packageLevel);
|
||||||
|
|
@ -269,8 +283,6 @@ export default {
|
||||||
nonpackageCartItems() {
|
nonpackageCartItems() {
|
||||||
const nonpackageCartItems = [];
|
const nonpackageCartItems = [];
|
||||||
|
|
||||||
console.log("packageCartItems");
|
|
||||||
|
|
||||||
this.cartItems.forEach((cartItem) => {
|
this.cartItems.forEach((cartItem) => {
|
||||||
if (cartItem == this.recycleFeeCartItem || cartItem == this.mobileFeeCartItem) {
|
if (cartItem == this.recycleFeeCartItem || cartItem == this.mobileFeeCartItem) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -299,7 +311,7 @@ export default {
|
||||||
cartItem = {
|
cartItem = {
|
||||||
name: this.frontWiperCartItemName,
|
name: this.frontWiperCartItemName,
|
||||||
category: cartItemCategories.VAPS,
|
category: cartItemCategories.VAPS,
|
||||||
cartItemType: cartItemTypes.FRONT_WIPER,
|
cartItemType: cartItemTypes.FRONT_WIPERS,
|
||||||
isDisplayed: true,
|
isDisplayed: true,
|
||||||
subTotal: 0,
|
subTotal: 0,
|
||||||
salesTax: 0,
|
salesTax: 0,
|
||||||
|
|
@ -335,7 +347,7 @@ export default {
|
||||||
cartItem = {
|
cartItem = {
|
||||||
name: this.rearWiperCartItemName,
|
name: this.rearWiperCartItemName,
|
||||||
category: cartItemCategories.VAPS,
|
category: cartItemCategories.VAPS,
|
||||||
cartItemType: cartItemTypes.REAR_WIPER,
|
cartItemType: cartItemTypes.REAR_WIPERS,
|
||||||
isDisplayed: true,
|
isDisplayed: true,
|
||||||
subTotal: 0,
|
subTotal: 0,
|
||||||
salesTax: 0,
|
salesTax: 0,
|
||||||
|
|
@ -394,61 +406,30 @@ export default {
|
||||||
glassPartsCartItem() {
|
glassPartsCartItem() {
|
||||||
let cartItem = null;
|
let cartItem = null;
|
||||||
|
|
||||||
const flattenedGlassPartsLineItems =
|
if (this.lineItems?.glassParts?.length > 0) {
|
||||||
this.lineItemUtilities.getFlattenedArrayOfLineItemsWithChildParts(
|
this.lineItems?.glassParts?.forEach((lineItem) => {
|
||||||
this.lineItems.glassParts
|
cartItem = {
|
||||||
);
|
name: null,
|
||||||
|
category: cartItemCategories.GLASS_PARTS,
|
||||||
|
cartItemType: cartItemTypes.GLASS_PARTS,
|
||||||
|
isDisplayed: false,
|
||||||
|
subTotal: (lineItem.kitPrice ?? 0) +
|
||||||
|
(lineItem.laborAmount ?? 0) +
|
||||||
|
(lineItem.sellingPrice ?? 0),
|
||||||
|
salesTax: lineItem.salesTax ?? 0,
|
||||||
|
lineItems: [],
|
||||||
|
};
|
||||||
|
|
||||||
if (flattenedGlassPartsLineItems.length > 0) {
|
if (lineItem.childParts?.length > 0) {
|
||||||
cartItem = {
|
lineItem.childParts.forEach((childPartLineItem) => {
|
||||||
name: null,
|
cartItem.subTotal += (childPartLineItem.kitPrice ?? 0) +
|
||||||
category: cartItemCategories.GLASS_PARTS,
|
(childPartLineItem.laborAmount ?? 0) +
|
||||||
cartItemType: cartItemTypes.GLASS_PARTS,
|
(childPartLineItem.sellingPrice ?? 0);
|
||||||
isDisplayed: false,
|
|
||||||
subTotal: 0,
|
|
||||||
salesTax: 0,
|
|
||||||
lineItems: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
flattenedGlassPartsLineItems.forEach((lineItem) => {
|
cartItem.salesTax += childPartLineItem.salesTax;
|
||||||
lineItem.cartItemType = cartItem.cartItemType;
|
})
|
||||||
cartItem.lineItems.push(lineItem);
|
}
|
||||||
|
|
||||||
cartItem.subTotal +=
|
|
||||||
(lineItem.kitPrice ?? 0) +
|
|
||||||
(lineItem.laborAmount ?? 0) +
|
|
||||||
(lineItem.sellingPrice ?? 0);
|
|
||||||
|
|
||||||
cartItem.salesTax += lineItem.salesTax ?? 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return cartItem;
|
|
||||||
},
|
|
||||||
supportingItemsCartItem() {
|
|
||||||
let cartItem = null;
|
|
||||||
|
|
||||||
if (this.supportingItems.length > 0) {
|
|
||||||
cartItem = {
|
|
||||||
name: null,
|
|
||||||
category: cartItemCategories.SUPPORTING_ITEMS,
|
|
||||||
cartItemType: cartItemTypes.SUPPORTING_ITEMS,
|
|
||||||
isDisplayed: false,
|
|
||||||
subTotal: 0,
|
|
||||||
salesTax: 0,
|
|
||||||
lineItems: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
this.supportingItems.forEach((lineItem) => {
|
|
||||||
lineItem.cartItemType = cartItem.cartItemType;
|
|
||||||
cartItem.lineItems.push(lineItem);
|
|
||||||
|
|
||||||
cartItem.subTotal +=
|
|
||||||
(lineItem.kitPrice ?? 0) +
|
|
||||||
(lineItem.laborAmount ?? 0) +
|
|
||||||
(lineItem.sellingPrice ?? 0);
|
|
||||||
|
|
||||||
cartItem.salesTax += lineItem.salesTax ?? 0;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,15 +456,15 @@ export default {
|
||||||
lineItems: [],
|
lineItems: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
recycleFeeLineItem.cartItemType = cartItem.cartItemType;
|
//recycleFeeLineItem.cartItemType = cartItem.cartItemType;
|
||||||
cartItem.lineItems.push(recycleFeeLineItem);
|
//cartItem.lineItems.push(recycleFeeLineItem);
|
||||||
|
|
||||||
cartItem.subTotal +=
|
cartItem.subTotal +=
|
||||||
(recycleFeeLineItem.kitPrice ?? 0) +
|
(recycleFeeLineItem.kitPrice ?? 0) +
|
||||||
(recycleFeeLineItem.laborAmount ?? 0) +
|
(recycleFeeLineItem.laborAmount ?? 0) +
|
||||||
(recycleFeeLineItem.sellingPrice ?? 0);
|
(recycleFeeLineItem.sellingPrice ?? 0);
|
||||||
|
|
||||||
cartItem.salesTax += recycleFeeLineItem.salesTax ?? 0;
|
cartItem.salesTax = recycleFeeLineItem.salesTax ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cartItem;
|
return cartItem;
|
||||||
|
|
@ -522,6 +503,37 @@ export default {
|
||||||
|
|
||||||
return cartItem;
|
return cartItem;
|
||||||
},
|
},
|
||||||
|
otherSupportingItemsCartItem() {
|
||||||
|
let cartItem = null;
|
||||||
|
|
||||||
|
const otherSupportingItemsLineItems = this.supportingItems.filter(lineItem => lineItem.partNumber != partTypeStrings.MOBILE_FEE && lineItem.partNumber != partTypeStrings.RECYCLE_FEE);
|
||||||
|
|
||||||
|
if (otherSupportingItemsLineItems.length > 0) {
|
||||||
|
cartItem = {
|
||||||
|
name: null,
|
||||||
|
category: cartItemCategories.SUPPORTING_ITEMS,
|
||||||
|
cartItemType: cartItemTypes.SUPPORTING_ITEMS,
|
||||||
|
isDisplayed: false,
|
||||||
|
subTotal: 0,
|
||||||
|
salesTax: 0,
|
||||||
|
lineItems: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
otherSupportingItemsLineItems.forEach((lineItem) => {
|
||||||
|
lineItem.cartItemType = cartItem.cartItemType;
|
||||||
|
cartItem.lineItems.push(lineItem);
|
||||||
|
|
||||||
|
cartItem.subTotal +=
|
||||||
|
(lineItem.kitPrice ?? 0) +
|
||||||
|
(lineItem.laborAmount ?? 0) +
|
||||||
|
(lineItem.sellingPrice ?? 0);
|
||||||
|
|
||||||
|
cartItem.salesTax += lineItem.salesTax ?? 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return cartItem;
|
||||||
|
},
|
||||||
removeLinkText() {
|
removeLinkText() {
|
||||||
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
|
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ import { defineRule } from "vee-validate";
|
||||||
import { required } from "@/helpers/validation-rules";
|
import { required } from "@/helpers/validation-rules";
|
||||||
import { errorMessages } from "@/constants/error-messages";
|
import { errorMessages } from "@/constants/error-messages";
|
||||||
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
||||||
import { LineItemUtilities, mapTaxedAvailableLineItemsToStoreFormat } from "../../store";
|
import { mapTaxedAvailableLineItemsToStoreFormat } from "../../store";
|
||||||
|
|
||||||
defineRule("option-required", required(errorMessages.OPTION_REQUIRED));
|
defineRule("option-required", required(errorMessages.OPTION_REQUIRED));
|
||||||
|
|
||||||
|
|
@ -174,9 +174,6 @@ export default {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
const lineItemUtilities = new LineItemUtilities();
|
|
||||||
lineItemUtilities.addGuidToLineItemsIfNotAlreadyThere(availableLineItems);
|
|
||||||
|
|
||||||
const lineItems = mapTaxedAvailableLineItemsToStoreFormat(
|
const lineItems = mapTaxedAvailableLineItemsToStoreFormat(
|
||||||
availableLineItems,
|
availableLineItems,
|
||||||
lineItemsFromStore
|
lineItemsFromStore
|
||||||
|
|
|
||||||
|
|
@ -1291,7 +1291,7 @@ export const actions = {
|
||||||
});
|
});
|
||||||
|
|
||||||
syncLineItemIds(response.data, context.getters.order.lineItems.vaps);
|
syncLineItemIds(response.data, context.getters.order.lineItems.vaps);
|
||||||
console.log(response.data);
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -2173,7 +2173,10 @@ export const actions = {
|
||||||
pageNameToLog,
|
pageNameToLog,
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const lineItemsWithOnlyPriceInfo = pricedAvailableLineItems.map((lineItem) => ({
|
const flattenedLineItemsWithChildParts =
|
||||||
|
getFlattenedArrayOfLineItemsWithChildParts(pricedAvailableLineItems);
|
||||||
|
|
||||||
|
const lineItemsWithOnlyPriceInfo = flattenedLineItemsWithChildParts.map((lineItem) => ({
|
||||||
partNumber: lineItem.partNumber,
|
partNumber: lineItem.partNumber,
|
||||||
laborAmount: lineItem.laborAmount ?? 0,
|
laborAmount: lineItem.laborAmount ?? 0,
|
||||||
kitPrice: lineItem.kitPrice ?? 0,
|
kitPrice: lineItem.kitPrice ?? 0,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue