From 9089da5d5a5421c1ed5cd26d565fdb079c901679 Mon Sep 17 00:00:00 2001 From: AdamCaouetteSafelite Date: Mon, 23 Jun 2025 12:33:40 -0400 Subject: [PATCH] CASH-926: adjust donation in cart without redoing pricing --- src/fmg-components/cart/cart.vue | 46 +++++++---------------- src/helpers/pricing-helper.js | 8 ++++ src/layouts/confirmation/confirmation.vue | 24 ++++++++++-- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/fmg-components/cart/cart.vue b/src/fmg-components/cart/cart.vue index 55e062e24..fb717d283 100644 --- a/src/fmg-components/cart/cart.vue +++ b/src/fmg-components/cart/cart.vue @@ -119,7 +119,7 @@
{{ donationCartItemName }} - {{ getLineItemAmount(donationCartItem.subTotal) }} + {{ getLineItemAmount(donationCartItem.sellingPrice) }}
{{ amountDueText }} @@ -182,6 +182,7 @@ import { getAmountDue, getSubTotal, getSalesTax, + getAmountDueWithDonation, } from "@/helpers/pricing-helper.js"; // Constants @@ -211,6 +212,7 @@ export default { isNoComp: Boolean, isExpandedOnLoad: Boolean, isMSRFeeApplicable: Boolean, + donationCartItem: Object, }, data() { return { @@ -1083,33 +1085,6 @@ export default { donationCartItemName() { return this.getCmsContent("DonationCartTextWidget", "Text"); }, - donationCartItem() { - if (!this.lineItems || !this.lineItems.supportingItems) { - return null; - } - - const donationLineItem = this.lineItems.supportingItems.find( - (item) => item.partType === partTypeStrings.DONATION - ); - - if (donationLineItem) { - return { - name: this.donationCartItemName, - category: cartItemCategories.SUPPORTING_ITEMS, - cartItemType: cartItemTypes.DONATION, - isDisplayed: true, - isRemovable: false, - subTotal: donationLineItem.sellingPrice, - salesTax: 0, - lineItems: [], - isCoveredByInsurance: cartItemTypesCoveredByInsurance.includes( - cartItemTypes.DONATION - ), - }; - } - - return null; - }, removeLinkText() { return this.getCmsContent("RemoveCartItemTextWidget", "Text"); }, @@ -1156,9 +1131,15 @@ export default { amountDue() { if (!this.lineItems || this.lineItems.length < 1) return; if (this.showAsPaid) return 0; - return this.isInsurance || !this.shouldHideRecalibration - ? getAmountDue(this.lineItems) // calculate with recal (if on order) - : getAmountDue(this.lineItemsWithoutRecal); // calculated without recal + if (this.isInsurance || !this.shouldHideRecalibration) { + return this.donationCartItem + ? getAmountDueWithDonation(this.lineItems, this.donationCartItem) + : getAmountDue(this.lineItems); + } else { + return this.donationCartItem + ? getAmountDueWithDonation(this.lineItemsWithoutRecal, this.donationCartItem) + : getAmountDue(this.lineItemsWithoutRecal); + } }, amountPaid() { if (!this.showAsPaid) { @@ -1311,8 +1292,7 @@ export default { .amount-due, .amount-paid, .donation-amount { - font-family: - UrbanistSemibold, AvertaSemibold; /* Okay to remove AvertaSemibold after 2025.06.19 merge/release */ + font-family: UrbanistSemibold; color: $black; } .sub-total { diff --git a/src/helpers/pricing-helper.js b/src/helpers/pricing-helper.js index fda5b3b9c..33311fd21 100644 --- a/src/helpers/pricing-helper.js +++ b/src/helpers/pricing-helper.js @@ -1,6 +1,7 @@ import store from "@/store"; import { storeActions } from "@/constants/store-actions"; import baseMixin from "@/mixins/base-mixin.js"; +import { deepClone } from "@/helpers/object-helper"; export function getDisplayAmountDue(lineItemsObject, includeTax = true) { return getAmountDue(lineItemsObject, includeTax).toLocaleString("en-US", { @@ -62,6 +63,13 @@ export function getSalesTax(lineItemsObject) { ); } +export function getAmountDueWithDonation(lineItemsObject, donationLineItem) { + // this is amount due with Donation added + const lineItemsCloneWithDonation = deepClone(lineItemsObject); + lineItemsCloneWithDonation.supportingItems.push(donationLineItem); + return getAmountDue(lineItemsCloneWithDonation, false); +} + export async function getPricingByDayPartWithPrice(pageNameToLog) { // Get the Pricing By Day Part const basePriceByDayPart = await baseMixin.methods.dispatchStoreActionWithLogging( diff --git a/src/layouts/confirmation/confirmation.vue b/src/layouts/confirmation/confirmation.vue index e65eacc3c..e8c01fd05 100644 --- a/src/layouts/confirmation/confirmation.vue +++ b/src/layouts/confirmation/confirmation.vue @@ -55,7 +55,8 @@ :damage="damageInfo" :availableVaps="vaps" :allowItemRemoval="false" - v-model="lineItems" + v-model="lineItemsWithoutDonation" + :donationCartItem="donationLineItem" :showAsPaid="isPia" servicePackageOptionsCmsName="ServicePackageTitle" :isInsurance="isInsurance" @@ -123,6 +124,7 @@ import experimentMixin from "@/mixins/experiment-mixin.js"; import { containsRecalParts } from "@/helpers/recal-helper.js"; import donationBlock from "@/experiment-components/donation-block.vue"; import { partNumberStrings } from "@/constants/part-number-strings"; +import { partTypeStrings } from "@/constants/part-type-strings"; import analyticsMixin from "@/mixins/analytics-mixin"; export default { @@ -229,7 +231,7 @@ export default { }; const donationItems = lineItemsFromSubmittedOrder.supportingItems?.filter( - (item) => item.partNumber === partNumberStrings.DONATION + (item) => item.partType === partTypeStrings.DONATION ); const donationAmount = donationItems?.length > 0 ? donationItems[0].sellingPrice : 0; @@ -243,7 +245,7 @@ export default { vm.shouldDisplayFosterLove = hasFosterLoveExperiment; vm.donationAmount = donationAmount; vm.showDonationSuccess = lineItemsFromSubmittedOrder.supportingItems?.some( - (item) => item.partType === partNumberStrings.DONATION + (item) => item.partType === partTypeStrings.DONATION ); vm.pushAnalytics(); @@ -490,6 +492,22 @@ export default { donationValues() { return [1, 3, 5]; }, + lineItemsWithoutDonation() { + const lineItemsClone = deepClone(this.lineItems); + lineItemsClone.supportingItems = lineItemsClone.supportingItems?.filter( + (item) => item.partType !== partTypeStrings.DONATION + ); + return lineItemsClone; + }, + donationLineItem() { + if (!this.lineItems) return null; + const donationLineItems = this.lineItems.supportingItems?.filter( + (item) => item.partType === partTypeStrings.DONATION + ); + let output = + donationLineItems && donationLineItems.length > 0 ? donationLineItems[0] : null; + return output; + }, }, methods: { arePagePrerequisitesValid() {