CSR-2237 found another cart price issue. Salestax was showing $13 on an order that was pending coverage. Changed salestax to return 0 for not verified insurance
267 lines
10 KiB
JavaScript
267 lines
10 KiB
JavaScript
import store from "@/store";
|
|
import { storeActions } from "@/constants/store-actions.js";
|
|
import { storeMutations } from "@/constants/store-mutations.js";
|
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
|
import { vehicleCategories } from "@/constants/vehicle-categories.js";
|
|
import { routerParams } from "@/router/router-constants/router-params";
|
|
import { queryStrings } from "@/constants/query-strings";
|
|
import { dynamicStrings } from "@/constants/dynamic-strings";
|
|
import { partTypeStrings } from "../constants/part-type-strings";
|
|
import { showFmgLoadingModal } from "@/helpers/loading-modal-helper";
|
|
import { getItemsWithoutRecalParts } from "@/helpers/recal-helper";
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
cmsContentByWidget: {},
|
|
};
|
|
},
|
|
methods: {
|
|
setCmsContent(cmsContent) {
|
|
this.$root.cmsContentByWidget = cmsContent;
|
|
},
|
|
getCmsContent(widgetName, fieldName) {
|
|
return this.$root.cmsContentByWidget?.[widgetName]?.[fieldName]
|
|
? this.$root.cmsContentByWidget[widgetName][fieldName]
|
|
: "";
|
|
},
|
|
dispatchStoreAction(type, payload, encodePayload = true) {
|
|
// Encode the payload if required
|
|
if (encodePayload) {
|
|
encodeUriData(payload);
|
|
}
|
|
|
|
return store.dispatch(type, payload);
|
|
},
|
|
dispatchStoreActionWithLogging(type, payload, pageNameToLog, encodePayload = true) {
|
|
// Encode the payload if required
|
|
if (encodePayload) {
|
|
encodeUriData(payload);
|
|
}
|
|
|
|
const wrappedParams = {
|
|
payload: payload,
|
|
pageNameToLog: pageNameToLog,
|
|
};
|
|
|
|
return store.dispatch(type, wrappedParams);
|
|
},
|
|
savePageDataToStore(page, data) {
|
|
store.commit(storeMutations.UPDATE_PAGE_DATA, { page: page, data: data });
|
|
},
|
|
onSubmit() {}, // DO NOT REMOVE; needed to prevent default form submit behavior. Cannot use .prevent modifier for vee-validate Form
|
|
onInvalidSubmit({ values, errors, results }) {
|
|
// identify the first error field and put focus on it
|
|
// get error names array
|
|
const errorNames = errors ? Object.keys(errors) : [];
|
|
const firstErrorEl = errorNames[0];
|
|
if (firstErrorEl) {
|
|
const qsString = "[data-focus-target='" + firstErrorEl + "']";
|
|
const el = document.querySelector(qsString);
|
|
el && el.focus();
|
|
}
|
|
},
|
|
getFooterInfoBoxHeight() {
|
|
const footerInfoBox = document.querySelector(".footer#infoBox");
|
|
return footerInfoBox ? footerInfoBox.offsetHeight : 0;
|
|
},
|
|
async getZipCodeData(zipCode, pageNameToLog = null) {
|
|
const pageName = pageNameToLog ?? this.$options?.name;
|
|
|
|
const serviceZipValidationResponse = await this.dispatchStoreActionWithLogging(
|
|
storeActions.VALIDATE_ZIP,
|
|
{ zip: zipCode },
|
|
pageName
|
|
);
|
|
|
|
return {
|
|
containsMilitaryBase: serviceZipValidationResponse.data.containsMilitaryBase,
|
|
isValid: serviceZipValidationResponse.data.isValid,
|
|
isServiceable: serviceZipValidationResponse.data.isServiceable,
|
|
state: serviceZipValidationResponse.data.state,
|
|
zipCodeCtu: serviceZipValidationResponse.data.zipCodeCtu,
|
|
};
|
|
},
|
|
getTierOnePackagePrice(lineItems) {
|
|
let lineItemsToPrice = lineItems?.filter((lineItem) => {
|
|
return (
|
|
lineItem.partType != partTypeStrings.FRONT_WIPER &&
|
|
lineItem.partType != partTypeStrings.REAR_WIPER &&
|
|
lineItem.partType != partTypeStrings.RAIN_DEFENSE
|
|
);
|
|
});
|
|
|
|
let totalPrice = this.getTotalPriceOfAllLineItemsAndChildParts(lineItemsToPrice, false);
|
|
return totalPrice;
|
|
},
|
|
filterOutFees(lineItems) {
|
|
const filteredLineItems = lineItems?.filter((item) => {
|
|
return (
|
|
(!item.partType.includes("FEE") && !item.partType.includes("EARLY BIRD")) ||
|
|
(item.partType === "REPAIR FEE" && item.partNumber != "SUPPLIES-REPAIR")
|
|
);
|
|
});
|
|
return filteredLineItems;
|
|
},
|
|
filterOutRecalibration(lineItems) {
|
|
return getItemsWithoutRecalParts(lineItems);
|
|
},
|
|
getTotalPriceOfAllLineItemsAndChildParts(lineItems, includeTax) {
|
|
let totalPrice = 0;
|
|
lineItems?.forEach((lineItem) => {
|
|
totalPrice += this.getTotalLineItemPrice(lineItem, includeTax);
|
|
if (lineItem.childParts) {
|
|
totalPrice += this.getTotalPriceOfAllLineItemsAndChildParts(
|
|
lineItem.childParts,
|
|
includeTax
|
|
);
|
|
}
|
|
});
|
|
return totalPrice;
|
|
},
|
|
getTotalLineItemPrice(lineItem, includeTax) {
|
|
if (includeTax) {
|
|
return (
|
|
lineItem.kitPrice +
|
|
lineItem.laborAmount +
|
|
lineItem.sellingPrice +
|
|
lineItem.salesTax
|
|
);
|
|
} else {
|
|
return lineItem.kitPrice + lineItem.laborAmount + lineItem.sellingPrice;
|
|
}
|
|
},
|
|
getDisplayAmountDue(lineItems) {
|
|
return this.getAmountDue(lineItems).toLocaleString("en-US", {
|
|
style: "currency",
|
|
currency: "USD",
|
|
});
|
|
},
|
|
getAmountDue(lineItems, includeTax = true) {
|
|
var amountDue = 0;
|
|
if (lineItems?.glassParts) {
|
|
amountDue += this.getTotalPriceOfAllLineItemsAndChildParts(
|
|
lineItems.glassParts,
|
|
includeTax
|
|
);
|
|
}
|
|
|
|
if (lineItems?.supportingItems) {
|
|
amountDue += this.getTotalPriceOfAllLineItemsAndChildParts(
|
|
lineItems.supportingItems,
|
|
includeTax
|
|
);
|
|
}
|
|
|
|
const order = this.hasSubmittedOrder() ? this.getSubmittedOrder() : store.getters.order;
|
|
if (
|
|
store.getters.coverageIsVerified &&
|
|
!order.policy.isNoComp &&
|
|
!order.policy.isItac
|
|
) {
|
|
amountDue = order.policy.currentDeductible;
|
|
}
|
|
|
|
if (lineItems?.vaps) {
|
|
amountDue += this.getTotalPriceOfAllLineItemsAndChildParts(
|
|
lineItems.vaps,
|
|
includeTax
|
|
);
|
|
}
|
|
|
|
if (lineItems?.promos) {
|
|
amountDue += this.getTotalPriceOfAllLineItemsAndChildParts(
|
|
lineItems.promos,
|
|
includeTax
|
|
);
|
|
}
|
|
|
|
return ((amountDue * 100) / 100).toFixed(2);
|
|
},
|
|
getSubTotal(lineItems) {
|
|
// this is amountDue without sales tax
|
|
return this.getAmountDue(lineItems, false);
|
|
},
|
|
getSalesTax(lineItems) {
|
|
// this is amountDue minus subTotal
|
|
return (
|
|
((this.getAmountDue(lineItems) - this.getSubTotal(lineItems)) * 100) /
|
|
100
|
|
).toFixed(2);
|
|
},
|
|
scrollToPageTop() {
|
|
const container = document.getElementsByClassName("page-container-grouped-styles")[0];
|
|
container.scrollTo({ top: 0, left: 0, behavior: "smooth" });
|
|
},
|
|
scrollToPageBottom() {
|
|
const container = document.getElementsByClassName("page-container-grouped-styles")[0];
|
|
container.scrollTo({ top: container.scrollHeight, left: 0, behavior: "smooth" });
|
|
},
|
|
ResetExternalParamsAndHideModal() {
|
|
this.dispatchStoreAction(storeActions.RESET_EXTERNAL_PARAMETER_STATE);
|
|
showFmgLoadingModal(false);
|
|
},
|
|
async isFormValid(form) {
|
|
const formValidateResponse = await form?.validate();
|
|
return formValidateResponse?.valid;
|
|
},
|
|
showApplePay() {
|
|
var iOSversion = this.getiOSversion();
|
|
var isMacOS = navigator.platform.indexOf("Mac") !== -1;
|
|
if (isMacOS || (iOSversion && iOSversion[0] >= 17)) {
|
|
if (window.ApplePaySession && window.ApplePaySession.canMakePayments()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
getiOSversion() {
|
|
if (/iP(hone|od|ad)/.test(navigator.platform)) {
|
|
// supports iOS 2.0 and later:
|
|
var v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
|
|
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
|
|
}
|
|
},
|
|
getSubmittedOrder() {
|
|
return JSON.parse(window.sessionStorage.getItem("submittedOrder"));
|
|
},
|
|
hasSubmittedOrder() {
|
|
return window.sessionStorage.getItem("submittedOrder") !== null;
|
|
},
|
|
},
|
|
computed: {
|
|
storeActions() {
|
|
return storeActions;
|
|
},
|
|
storeMutations() {
|
|
return storeMutations;
|
|
},
|
|
navigationScenarios() {
|
|
return navigationScenarios;
|
|
},
|
|
vehicleCategories() {
|
|
return vehicleCategories;
|
|
},
|
|
routerParams() {
|
|
return routerParams;
|
|
},
|
|
queryStrings() {
|
|
return queryStrings;
|
|
},
|
|
dynamicStrings() {
|
|
return dynamicStrings;
|
|
},
|
|
cssClassNameForCmsWidget() {
|
|
return "widget-name-" + this.cmsWidgetName;
|
|
},
|
|
},
|
|
};
|
|
|
|
function encodeUriData(payload) {
|
|
if (payload && Object.keys(payload).length > 0) {
|
|
// Loop through the payload and encode the values
|
|
Object.keys(payload).forEach((key) => {
|
|
payload[key] = encodeURIComponent(payload[key]);
|
|
});
|
|
}
|
|
}
|