diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index 1d1ba13b8..0d116fb10 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -55,7 +55,15 @@ {{ recycleFeeCartItem.name }} - {{ currencyFormatter.format(cartItem.subTotal) }} + {{ + `${ + cartItem.category == "promos" + ? "(" + currencyFormatter.format(cartItem.subTotal * -1) + ")" + : currencyFormatter.format(cartItem.subTotal) + }` + }} + @@ -95,6 +103,7 @@ import baseMixin from "@/mixins/base-mixin.js"; // Helpers import { deepClone } from "@/helpers/object-helper"; import { getHighestFullySatisfiedTier, getPackageContents } from "@/helpers/service-package-helper"; +import { getPromoCodeWithoutBundleIdentifier } from "@/helpers/promotions-helper"; // Constants import { partTypeStrings } from "@/constants/part-type-strings"; @@ -224,33 +233,16 @@ export default { cartItems.push(this.mobileFeeCartItem); } - // Create a cart item for each promo - this.promos.forEach((promoLineItem) => { - let cartItem = null; - - cartItem = { - name: promoLineItem?.promoCode, // get from CMS? - category: cartItemCategories.PROMOS, - cartItemType: promoLineItem?.partType, - isDisplayed: true, - subTotal: - (promoLineItem?.kitPrice ?? 0) + - (promoLineItem?.laborAmount ?? 0) + - (promoLineItem?.sellingPrice ?? 0), - salesTax: promoLineItem?.salesTax, - lineItems: [], - }; - - promoLineItem.cartItemType = cartItem.cartItemType; - cartItem.lineItems.push(promoLineItem); - - cartItems.push(cartItem); - }); - if (this.premiumAppointmentDiscountCartItem) { cartItems.push(this.premiumAppointmentDiscountCartItem); } + if (this.promoCartItems) { + this.promoCartItems.forEach((promoCartItem) => { + cartItems.push(promoCartItem); + }); + } + return cartItems; }, }, @@ -353,6 +345,7 @@ export default { category: cartItemCategories.VAPS, cartItemType: cartItemTypes.FRONT_WIPERS, isDisplayed: true, + isRemovable: true, subTotal: 0, salesTax: 0, lineItems: [], @@ -555,10 +548,7 @@ export default { otherSupportingItemsCartItem() { let cartItem = null; - let otherSupportingItemsLineItems = baseMixin.methods.filterOutFees( - this.supportingItems - ); - otherSupportingItemsLineItems = otherSupportingItemsLineItems.filter( + const otherSupportingItemsLineItems = this.supportingItems.filter( (lineItem) => lineItem.partType != partTypeStrings.EARLY_BIRD ); @@ -605,6 +595,7 @@ export default { category: cartItemCategories.SUPPORTING_ITEMS, cartItemType: cartItemTypes.EARLY_BIRD, isDisplayed: true, + isRemovable: true, subTotal: 0, salesTax: 0, lineItems: [], @@ -623,6 +614,57 @@ export default { return cartItem; }, + promoCartItems() { + const promoCartItems = []; + + // clone the promos array + const promosClone = deepClone(this.promo); + // get unique promo codes + const uniquePromoCodes = [ + ...new Set( + this.promos.map((promo) => getPromoCodeWithoutBundleIdentifier(promo.promoCode)) + ), + ]; + + uniquePromoCodes.forEach((promoCode) => { + // get the codes with the prefix from the promo array + const promoLineItems = this.promos.filter( + (promo) => getPromoCodeWithoutBundleIdentifier(promo.promoCode) == promoCode + ); + + // Create a cart item for each promo + let cartItem = null; + + cartItem = { + name: promoCode, + category: cartItemCategories.PROMOS, + cartItemType: promoCode, + isDisplayed: true, + isRemovable: true, + subTotal: 0, + salesTax: 0, + lineItems: [], + }; + + promoLineItems.forEach((promoLineItem) => { + promoLineItem.cartItemType = cartItem.cartItemType; + + cartItem.subTotal += + (promoLineItem.kitPrice ?? 0) + + (promoLineItem.laborAmount ?? 0) + + (promoLineItem.sellingPrice ?? 0); + + cartItem.salesTax += promoLineItem.salesTax ?? 0; + + cartItem.lineItems.push(promoLineItem); + }); + + promoCartItems.push(cartItem); + }); + + return promoCartItems; + }, + removeLinkText() { return this.getCmsContent("RemoveCartItemTextWidget", "Text"); }, diff --git a/src/helpers/date-helper.js b/src/helpers/date-helper.js index 756863765..482440431 100644 --- a/src/helpers/date-helper.js +++ b/src/helpers/date-helper.js @@ -5,7 +5,7 @@ export function getDateDifferenceInDays(startDate, endDate) { // Use the built-in method to get the difference in milliseconds var difference = date1 - date2; // Convert milliseconds to days and return the result - return difference / (1000 * 3600 * 24); + return Math.floor(difference / (1000 * 3600 * 24)); } export function get12HourTimeFormat(time) { // Check correct time format and split into components