Fixed calculation issue, added promo cart items

This commit is contained in:
Leah Schumann 2023-10-30 15:46:48 -04:00
parent 3ed90a29c1
commit 5583070c2c
4 changed files with 92 additions and 79 deletions

View file

@ -1,11 +1,12 @@
const cartItemTypes = {
FRONT_WIPER: "FRONT WIPER",
REAR_WIPER: "REAR WIPER",
FRONT_WIPERS: "FRONT WIPERS",
REAR_WIPERS: "REAR WIPERS",
SUPPORTING_ITEMS: "SUPPORTING ITEMS",
GLASS_PARTS: "GLASS PARTS",
RAIN_DEFENSE: "RAIN DEFENSE",
RECYCLE_FEE: "RECYCLE FEE",
MOBILE_FEE: "MOBILE FEE",
PROMOS: "PROMOS",
};
export { cartItemTypes };

View file

@ -129,11 +129,9 @@ export default {
let vapsCartItemsForSelectedPackage = [];
console.log(this.cartItems);
console.log(packageContentTypes);
this.cartItems.forEach((cartItem) => {
packageContentTypes.forEach((vapType) => {
if (vapType == cartItem.cartItemType) {
if (cartItem.cartItemType.includes(vapType)) {
vapsCartItemsForSelectedPackage.push(cartItem);
}
});
@ -153,17 +151,10 @@ export default {
return vapsTypeName.Text;
},
removeItem(cartItemType, category) {
console.log(
this.lineItems[category].filter(
(lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType
)
);
this.lineItems[category] = this.lineItems[category].filter(
(lineItemsToKeep) => lineItemsToKeep.cartItemType != cartItemType
);
//console.log(`lineItemToDelete: ${lineItemIdToDelete}`)
this.$emit("update:modelValue", this.lineItems);
},
},
@ -188,8 +179,8 @@ export default {
cartItems.push(this.glassPartsCartItem);
}
if (this.supportingItemsCartItem) {
cartItems.push(this.supportingItemsCartItem);
if (this.otherSupportingItemsCartItem) {
cartItems.push(this.otherSupportingItemsCartItem);
}
if (this.recycleFeeCartItem) {
@ -200,6 +191,25 @@ export default {
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;
},
},
@ -262,6 +272,10 @@ export default {
const supportingItems = this.lineItems?.supportingItems;
return supportingItems?.length > 0 ? supportingItems : [];
},
promos() {
const promos = this.lineItems?.promos;
return promos?.length > 0 ? promos : [];
},
// Cart Items
packageCartItems() {
return this.getVapsCartItemsForSelectedPackage(this.packageLevel);
@ -269,8 +283,6 @@ export default {
nonpackageCartItems() {
const nonpackageCartItems = [];
console.log("packageCartItems");
this.cartItems.forEach((cartItem) => {
if (cartItem == this.recycleFeeCartItem || cartItem == this.mobileFeeCartItem) {
return;
@ -299,7 +311,7 @@ export default {
cartItem = {
name: this.frontWiperCartItemName,
category: cartItemCategories.VAPS,
cartItemType: cartItemTypes.FRONT_WIPER,
cartItemType: cartItemTypes.FRONT_WIPERS,
isDisplayed: true,
subTotal: 0,
salesTax: 0,
@ -335,7 +347,7 @@ export default {
cartItem = {
name: this.rearWiperCartItemName,
category: cartItemCategories.VAPS,
cartItemType: cartItemTypes.REAR_WIPER,
cartItemType: cartItemTypes.REAR_WIPERS,
isDisplayed: true,
subTotal: 0,
salesTax: 0,
@ -394,61 +406,30 @@ export default {
glassPartsCartItem() {
let cartItem = null;
const flattenedGlassPartsLineItems =
this.lineItemUtilities.getFlattenedArrayOfLineItemsWithChildParts(
this.lineItems.glassParts
);
if (this.lineItems?.glassParts?.length > 0) {
this.lineItems?.glassParts?.forEach((lineItem) => {
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) {
cartItem = {
name: null,
category: cartItemCategories.GLASS_PARTS,
cartItemType: cartItemTypes.GLASS_PARTS,
isDisplayed: false,
subTotal: 0,
salesTax: 0,
lineItems: [],
};
if (lineItem.childParts?.length > 0) {
lineItem.childParts.forEach((childPartLineItem) => {
cartItem.subTotal += (childPartLineItem.kitPrice ?? 0) +
(childPartLineItem.laborAmount ?? 0) +
(childPartLineItem.sellingPrice ?? 0);
flattenedGlassPartsLineItems.forEach((lineItem) => {
lineItem.cartItemType = cartItem.cartItemType;
cartItem.lineItems.push(lineItem);
cartItem.salesTax += childPartLineItem.salesTax;
})
}
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: [],
};
recycleFeeLineItem.cartItemType = cartItem.cartItemType;
cartItem.lineItems.push(recycleFeeLineItem);
//recycleFeeLineItem.cartItemType = cartItem.cartItemType;
//cartItem.lineItems.push(recycleFeeLineItem);
cartItem.subTotal +=
(recycleFeeLineItem.kitPrice ?? 0) +
(recycleFeeLineItem.laborAmount ?? 0) +
(recycleFeeLineItem.sellingPrice ?? 0);
cartItem.salesTax += recycleFeeLineItem.salesTax ?? 0;
cartItem.salesTax = recycleFeeLineItem.salesTax ?? 0;
}
return cartItem;
@ -522,6 +503,37 @@ export default {
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() {
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
},

View file

@ -90,7 +90,7 @@ import { defineRule } from "vee-validate";
import { required } from "@/helpers/validation-rules";
import { errorMessages } from "@/constants/error-messages";
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
import { LineItemUtilities, mapTaxedAvailableLineItemsToStoreFormat } from "../../store";
import { mapTaxedAvailableLineItemsToStoreFormat } from "../../store";
defineRule("option-required", required(errorMessages.OPTION_REQUIRED));
@ -174,9 +174,6 @@ export default {
false
);
const lineItemUtilities = new LineItemUtilities();
lineItemUtilities.addGuidToLineItemsIfNotAlreadyThere(availableLineItems);
const lineItems = mapTaxedAvailableLineItemsToStoreFormat(
availableLineItems,
lineItemsFromStore

View file

@ -1291,7 +1291,7 @@ export const actions = {
});
syncLineItemIds(response.data, context.getters.order.lineItems.vaps);
console.log(response.data);
return response;
},
@ -2173,7 +2173,10 @@ export const actions = {
pageNameToLog,
}
) {
const lineItemsWithOnlyPriceInfo = pricedAvailableLineItems.map((lineItem) => ({
const flattenedLineItemsWithChildParts =
getFlattenedArrayOfLineItemsWithChildParts(pricedAvailableLineItems);
const lineItemsWithOnlyPriceInfo = flattenedLineItemsWithChildParts.map((lineItem) => ({
partNumber: lineItem.partNumber,
laborAmount: lineItem.laborAmount ?? 0,
kitPrice: lineItem.kitPrice ?? 0,