Merge pull request #2375 from Safelite/feature/CASH-413
CASH-413: Update recycle fee on location change
This commit is contained in:
commit
199aff5cd1
6 changed files with 134 additions and 10 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
import baseMixin from "@/mixins/base-mixin.js";
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
|
import { partNumberStrings } from "@/constants/part-number-strings";
|
||||||
|
|
||||||
export async function getPricedMobileFeePart(serviceZipCode, pageNameToLog) {
|
export async function getPricedMobileFeePart(serviceZipCode, pageNameToLog) {
|
||||||
if (!serviceZipCode) {
|
if (!serviceZipCode) {
|
||||||
|
|
@ -42,6 +43,50 @@ export async function getPricedMobileFeePart(serviceZipCode, pageNameToLog) {
|
||||||
return pricingResults[0];
|
return pricingResults[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getPricedRecycleFeePart(serviceZipCode, pageNameToLog) {
|
||||||
|
if (!serviceZipCode) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zipCodeData = await getZipCodeData(serviceZipCode);
|
||||||
|
|
||||||
|
// Get supporting items
|
||||||
|
const supportingItems = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
|
storeActions.GET_SUPPORTING_ITEMS,
|
||||||
|
null,
|
||||||
|
pageNameToLog,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
supportingItems.data === null ||
|
||||||
|
supportingItems.data === undefined ||
|
||||||
|
supportingItems.data === ""
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const recycleFeePart = supportingItems.data.find(
|
||||||
|
(item) => item.partNumber === partNumberStrings.RECYCLE_FEE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (recycleFeePart) {
|
||||||
|
// Get the Recycle Fee Part Price
|
||||||
|
const pricingResults = await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
|
storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA,
|
||||||
|
{
|
||||||
|
availableLineItems: [recycleFeePart],
|
||||||
|
serviceZipCode: serviceZipCode,
|
||||||
|
serviceZipCodeCtu: zipCodeData.zipCodeCtu,
|
||||||
|
},
|
||||||
|
pageNameToLog,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
return pricingResults[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getServiceabilityDetails(serviceZipCode, lineItems, pageNameToLog) {
|
export async function getServiceabilityDetails(serviceZipCode, lineItems, pageNameToLog) {
|
||||||
// Get the Mobile Fee Part
|
// Get the Mobile Fee Part
|
||||||
return await baseMixin.methods.dispatchStoreActionWithLogging(
|
return await baseMixin.methods.dispatchStoreActionWithLogging(
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,23 @@ const mockGetPricedMobileFeePart = (mockServiceZipCode) => {
|
||||||
return Promise.resolve(mobileFeePart);
|
return Promise.resolve(mobileFeePart);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockGetPricedRecycleFeePart = (mockServiceZipCode) => {
|
||||||
|
let recycleFeePart = {};
|
||||||
|
|
||||||
|
if (mockServiceZipCode === "43235") {
|
||||||
|
recycleFeePart = {
|
||||||
|
partNumber: "RECYCLE FEE",
|
||||||
|
description: "RECYCLE FEE",
|
||||||
|
partType: "FEE",
|
||||||
|
laborAmount: 39.99,
|
||||||
|
sellingPrice: 0,
|
||||||
|
kitPrice: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(recycleFeePart);
|
||||||
|
};
|
||||||
|
|
||||||
const mockGetServiceabilityDetails = (mockServiceZipCode) => {
|
const mockGetServiceabilityDetails = (mockServiceZipCode) => {
|
||||||
const serviceabilityDetails = {
|
const serviceabilityDetails = {
|
||||||
isGlassServiceableInshop: true,
|
isGlassServiceableInshop: true,
|
||||||
|
|
@ -123,6 +140,9 @@ jest.mock(
|
||||||
getPricedMobileFeePart: jest.fn((mockServiceZipCode) => {
|
getPricedMobileFeePart: jest.fn((mockServiceZipCode) => {
|
||||||
return mockGetPricedMobileFeePart(mockServiceZipCode);
|
return mockGetPricedMobileFeePart(mockServiceZipCode);
|
||||||
}),
|
}),
|
||||||
|
getPricedRecycleFeePart: jest.fn((mockServiceZipCode) => {
|
||||||
|
return mockGetPricedRecycleFeePart(mockServiceZipCode);
|
||||||
|
}),
|
||||||
getServiceabilityDetails: jest.fn((mockServiceZipCode) => {
|
getServiceabilityDetails: jest.fn((mockServiceZipCode) => {
|
||||||
return mockGetServiceabilityDetails(mockServiceZipCode);
|
return mockGetServiceabilityDetails(mockServiceZipCode);
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location
|
||||||
import { deepClone } from "@/helpers/object-helper";
|
import { deepClone } from "@/helpers/object-helper";
|
||||||
import {
|
import {
|
||||||
getPricedMobileFeePart,
|
getPricedMobileFeePart,
|
||||||
|
getPricedRecycleFeePart,
|
||||||
getServiceabilityDetails,
|
getServiceabilityDetails,
|
||||||
getBillToAccountNumber,
|
getBillToAccountNumber,
|
||||||
} from "@/layouts/service-location/helpers/service-location-helper/service-location-helper";
|
} from "@/layouts/service-location/helpers/service-location-helper/service-location-helper";
|
||||||
|
|
@ -267,6 +268,12 @@ export default {
|
||||||
"service-location"
|
"service-location"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// retrieve recycle fee part
|
||||||
|
const recycleFeePart = await getPricedRecycleFeePart(
|
||||||
|
serviceZipCode,
|
||||||
|
"service-location"
|
||||||
|
);
|
||||||
|
|
||||||
// retrieve serviceability details
|
// retrieve serviceability details
|
||||||
const serviceabilityDetails = await getServiceabilityDetails(
|
const serviceabilityDetails = await getServiceabilityDetails(
|
||||||
serviceZipCode,
|
serviceZipCode,
|
||||||
|
|
@ -280,6 +287,7 @@ export default {
|
||||||
|
|
||||||
// update content related to service zip code
|
// update content related to service zip code
|
||||||
this.$emit("updated-mobile-fee-part", mobileFeePart);
|
this.$emit("updated-mobile-fee-part", mobileFeePart);
|
||||||
|
this.$emit("updated-recycle-fee-part", recycleFeePart);
|
||||||
this.$emit("updated-serviceability", serviceabilityDetails.data);
|
this.$emit("updated-serviceability", serviceabilityDetails.data);
|
||||||
this.$emit("updated-contains-military-base", zipCodeData.containsMilitaryBase);
|
this.$emit("updated-contains-military-base", zipCodeData.containsMilitaryBase);
|
||||||
this.$emit("updated-mobile-ctu", zipCodeData.zipCodeCtu);
|
this.$emit("updated-mobile-ctu", zipCodeData.zipCodeCtu);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
ref="serviceZipCodeQuestion"
|
ref="serviceZipCodeQuestion"
|
||||||
:mobileFeePart="mobileFeePart"
|
:mobileFeePart="mobileFeePart"
|
||||||
@updated-mobile-fee-part="setMobileFeePart"
|
@updated-mobile-fee-part="setMobileFeePart"
|
||||||
|
@updated-recycle-fee-part="setRecycleFeePart"
|
||||||
@updated-serviceability="setServiceabilityDetails"
|
@updated-serviceability="setServiceabilityDetails"
|
||||||
@updated-contains-military-base="setContainsMilitaryBase"
|
@updated-contains-military-base="setContainsMilitaryBase"
|
||||||
@updated-bill-to-account-number="setBillToAccountNumber"
|
@updated-bill-to-account-number="setBillToAccountNumber"
|
||||||
|
|
@ -90,6 +91,7 @@
|
||||||
:mobileFeePart="mobileFeePart"
|
:mobileFeePart="mobileFeePart"
|
||||||
:mobileFeeApplies="mobileFeeApplies"
|
:mobileFeeApplies="mobileFeeApplies"
|
||||||
@updated-mobile-fee-part="setMobileFeePart"
|
@updated-mobile-fee-part="setMobileFeePart"
|
||||||
|
@updated-recycle-fee-part="setRecycleFeePart"
|
||||||
@updated-serviceability="setServiceabilityDetails"
|
@updated-serviceability="setServiceabilityDetails"
|
||||||
@updated-contains-military-base="setContainsMilitaryBase"
|
@updated-contains-military-base="setContainsMilitaryBase"
|
||||||
@updated-mobile-ctu="setCtuForMobile"
|
@updated-mobile-ctu="setCtuForMobile"
|
||||||
|
|
@ -195,6 +197,7 @@ export default {
|
||||||
selectedAppointmentType: this.getSelectedAppointmentType(),
|
selectedAppointmentType: this.getSelectedAppointmentType(),
|
||||||
selectedProvider: this.getSelectedProvider(),
|
selectedProvider: this.getSelectedProvider(),
|
||||||
mobileFeePart: null,
|
mobileFeePart: null,
|
||||||
|
recycleFeePart: null,
|
||||||
zipContainsMilitaryBase: false,
|
zipContainsMilitaryBase: false,
|
||||||
zipCodeCtu: null,
|
zipCodeCtu: null,
|
||||||
billToAccountNumber: null,
|
billToAccountNumber: null,
|
||||||
|
|
@ -480,6 +483,9 @@ export default {
|
||||||
setMobileFeePart(mobileFeePart) {
|
setMobileFeePart(mobileFeePart) {
|
||||||
this.mobileFeePart = mobileFeePart;
|
this.mobileFeePart = mobileFeePart;
|
||||||
},
|
},
|
||||||
|
setRecycleFeePart(recycleFeePart) {
|
||||||
|
this.recycleFeePart = recycleFeePart;
|
||||||
|
},
|
||||||
//creating async function as the computed property can not directly handle asynchronous operations or promises.
|
//creating async function as the computed property can not directly handle asynchronous operations or promises.
|
||||||
async setMobileLocationQuestions(newValue) {
|
async setMobileLocationQuestions(newValue) {
|
||||||
var newZipCode = newValue.addressQuestions.zipCode;
|
var newZipCode = newValue.addressQuestions.zipCode;
|
||||||
|
|
@ -592,6 +598,7 @@ export default {
|
||||||
},
|
},
|
||||||
updateAndSaveSupportingItems() {
|
updateAndSaveSupportingItems() {
|
||||||
let supportingItems = store.getters.lineItems.supportingItems;
|
let supportingItems = store.getters.lineItems.supportingItems;
|
||||||
|
let shouldSaveSupportingItems = false;
|
||||||
|
|
||||||
supportingItems =
|
supportingItems =
|
||||||
!supportingItems && this.isMobileStaticRecalibrationApplicable
|
!supportingItems && this.isMobileStaticRecalibrationApplicable
|
||||||
|
|
@ -603,6 +610,21 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update recyle fee price
|
||||||
|
if (this.recycleFeePart) {
|
||||||
|
const recycleFeeIndex = supportingItems.findIndex(
|
||||||
|
(item) => item.partNumber == partNumberStrings.RECYCLE_FEE
|
||||||
|
);
|
||||||
|
if (recycleFeeIndex >= 0) {
|
||||||
|
supportingItems[recycleFeeIndex].laborAmount = this.recycleFeePart.laborAmount;
|
||||||
|
supportingItems[recycleFeeIndex].sellingPrice =
|
||||||
|
this.recycleFeePart.sellingPrice;
|
||||||
|
supportingItems[recycleFeeIndex].kitPrice = this.recycleFeePart.kitPrice;
|
||||||
|
|
||||||
|
shouldSaveSupportingItems = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if we have a mobile fee, then save/update supporting items
|
// if we have a mobile fee, then save/update supporting items
|
||||||
if (this.selectedAppointmentType == "Mobile") {
|
if (this.selectedAppointmentType == "Mobile") {
|
||||||
const mobileFeeIndex = supportingItems.findIndex(
|
const mobileFeeIndex = supportingItems.findIndex(
|
||||||
|
|
@ -617,11 +639,7 @@ export default {
|
||||||
if (this.mobileFeePart !== null) supportingItems.push(this.mobileFeePart);
|
if (this.mobileFeePart !== null) supportingItems.push(this.mobileFeePart);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dispatchStoreAction(
|
shouldSaveSupportingItems = true;
|
||||||
this.storeActions.SAVE_SUPPORTING_ITEMS_SUPPRESSING_STATE_RESETTING,
|
|
||||||
supportingItems,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// if it's not a mobile, then make sure we remove any that may have been added
|
// if it's not a mobile, then make sure we remove any that may have been added
|
||||||
const removeMobileFeeIndex = supportingItems?.findIndex(
|
const removeMobileFeeIndex = supportingItems?.findIndex(
|
||||||
|
|
@ -630,13 +648,18 @@ export default {
|
||||||
|
|
||||||
if (removeMobileFeeIndex >= 0) {
|
if (removeMobileFeeIndex >= 0) {
|
||||||
supportingItems.splice(removeMobileFeeIndex, 1);
|
supportingItems.splice(removeMobileFeeIndex, 1);
|
||||||
this.dispatchStoreAction(
|
shouldSaveSupportingItems = true;
|
||||||
this.storeActions.SAVE_SUPPORTING_ITEMS_SUPPRESSING_STATE_RESETTING,
|
|
||||||
supportingItems,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use shouldSaveSupportingItems flag to determine if we need to save supporting items. Prevents unnecessary/multiple saves
|
||||||
|
if (shouldSaveSupportingItems) {
|
||||||
|
this.dispatchStoreAction(
|
||||||
|
this.storeActions.SAVE_SUPPORTING_ITEMS_SUPPRESSING_STATE_RESETTING,
|
||||||
|
supportingItems,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async forwardButtonAction() {
|
async forwardButtonAction() {
|
||||||
this.navigatingForward = true;
|
this.navigatingForward = true;
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,23 @@ const mockGetPricedMobileFeePart = (mockServiceZipCode) => {
|
||||||
return Promise.resolve(mobileFeePart);
|
return Promise.resolve(mobileFeePart);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockGetPricedRecycleFeePart = (mockServiceZipCode) => {
|
||||||
|
let recycleFeePart = {};
|
||||||
|
|
||||||
|
if (mockServiceZipCode === "43235") {
|
||||||
|
recycleFeePart = {
|
||||||
|
partNumber: "RECYCLE FEE",
|
||||||
|
description: "RECYCLE FEE",
|
||||||
|
partType: "FEE",
|
||||||
|
laborAmount: 39.99,
|
||||||
|
sellingPrice: 0,
|
||||||
|
kitPrice: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(recycleFeePart);
|
||||||
|
};
|
||||||
|
|
||||||
const mockGetServiceabilityDetails = (mockServiceZipCode) => {
|
const mockGetServiceabilityDetails = (mockServiceZipCode) => {
|
||||||
const serviceabilityDetails = {
|
const serviceabilityDetails = {
|
||||||
isGlassServiceableInshop: true,
|
isGlassServiceableInshop: true,
|
||||||
|
|
@ -49,6 +66,9 @@ jest.mock(
|
||||||
getPricedMobileFeePart: jest.fn((mockServiceZipCode) => {
|
getPricedMobileFeePart: jest.fn((mockServiceZipCode) => {
|
||||||
return mockGetPricedMobileFeePart(mockServiceZipCode);
|
return mockGetPricedMobileFeePart(mockServiceZipCode);
|
||||||
}),
|
}),
|
||||||
|
getPricedRecycleFeePart: jest.fn((mockServiceZipCode) => {
|
||||||
|
return mockGetPricedRecycleFeePart(mockServiceZipCode);
|
||||||
|
}),
|
||||||
getServiceabilityDetails: jest.fn((mockServiceZipCode) => {
|
getServiceabilityDetails: jest.fn((mockServiceZipCode) => {
|
||||||
return mockGetServiceabilityDetails(mockServiceZipCode);
|
return mockGetServiceabilityDetails(mockServiceZipCode);
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ import alert from "@/ux-components/alert/alert";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getPricedMobileFeePart,
|
getPricedMobileFeePart,
|
||||||
|
getPricedRecycleFeePart,
|
||||||
getServiceabilityDetails,
|
getServiceabilityDetails,
|
||||||
getBillToAccountNumber,
|
getBillToAccountNumber,
|
||||||
} from "@/layouts/service-location/helpers/service-location-helper/service-location-helper";
|
} from "@/layouts/service-location/helpers/service-location-helper/service-location-helper";
|
||||||
|
|
@ -164,6 +165,12 @@ export default {
|
||||||
"service-location"
|
"service-location"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// retrieve recycle fee part
|
||||||
|
const recycleFeePart = await getPricedRecycleFeePart(
|
||||||
|
serviceZipCode,
|
||||||
|
"service-location"
|
||||||
|
);
|
||||||
|
|
||||||
// retrieve serviceability details
|
// retrieve serviceability details
|
||||||
const serviceabilityDetails = await getServiceabilityDetails(
|
const serviceabilityDetails = await getServiceabilityDetails(
|
||||||
serviceZipCode,
|
serviceZipCode,
|
||||||
|
|
@ -177,6 +184,7 @@ export default {
|
||||||
|
|
||||||
// update content related to service zip code
|
// update content related to service zip code
|
||||||
this.$emit("updated-mobile-fee-part", mobileFeePart);
|
this.$emit("updated-mobile-fee-part", mobileFeePart);
|
||||||
|
this.$emit("updated-recycle-fee-part", recycleFeePart);
|
||||||
this.$emit("updated-serviceability", serviceabilityDetails.data);
|
this.$emit("updated-serviceability", serviceabilityDetails.data);
|
||||||
this.$emit("updated-contains-military-base", zipCodeData.containsMilitaryBase);
|
this.$emit("updated-contains-military-base", zipCodeData.containsMilitaryBase);
|
||||||
this.$emit("updated-bill-to-account-number", billToAccountNumber);
|
this.$emit("updated-bill-to-account-number", billToAccountNumber);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue