Merge pull request #2014 from Safelite/feature/CSR-2150
CSR-2150 | Make promos work with Recal
This commit is contained in:
commit
8e586f1fa2
2 changed files with 29 additions and 11 deletions
|
|
@ -30,7 +30,7 @@
|
|||
import { splitCopyOnCMSPlaceHolder } from "@/helpers/cms-content-helper";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
import { getPromosThatMatchLineItemsOnOrder } from "@/helpers/promotions-helper";
|
||||
import { getArrayOfAllLineItems } from "@/store";
|
||||
import { getArrayOfAllLineItemsAndChildParts } from "@/store";
|
||||
|
||||
const INLINE_IMAGE_TOKEN = "custom:inlineImage";
|
||||
const AFTERPAY_PRICE_TOKEN = "custom:afterpayPrice";
|
||||
|
|
@ -76,7 +76,7 @@ export default {
|
|||
return this.getCmsContent(this.cmsWidgetName, "SubheaderText");
|
||||
},
|
||||
afterpayPrice() {
|
||||
let allLineItems = getArrayOfAllLineItems(this.lineItems);
|
||||
let allLineItems = getArrayOfAllLineItemsAndChildParts(this.lineItems);
|
||||
if (this.lineItems.promos) {
|
||||
allLineItems = allLineItems?.filter((item) => item.partType !== "PROMO_DISCOUNT");
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ export default {
|
|||
});
|
||||
|
||||
if (this.lineItems.promos) {
|
||||
let allLineItems = getArrayOfAllLineItems(this.lineItems);
|
||||
let allLineItems = getArrayOfAllLineItemsAndChildParts(this.lineItems);
|
||||
const promos = getPromosThatMatchLineItemsOnOrder(
|
||||
this.lineItems.promos,
|
||||
allLineItems
|
||||
|
|
|
|||
|
|
@ -2617,7 +2617,7 @@ export const actions = {
|
|||
eon: order.eon,
|
||||
isRepair: order.damage.isRepair,
|
||||
glassToReplace: renameGlassToReplaceAttributes(order.damage.glassToReplace),
|
||||
lineItemsOnOrder: getArrayOfAllLineItems(lineItemsToUse),
|
||||
lineItemsOnOrder: getArrayOfAllLineItemsAndChildParts(lineItemsToUse),
|
||||
parentAccountNumber: useDefaultCashParentAccount
|
||||
? applicationConfig.CASH_PARENT_ACCOUNT_NUMBER
|
||||
: order.payment.parentAccountNumber,
|
||||
|
|
@ -2689,7 +2689,7 @@ export const actions = {
|
|||
eon: order.eon,
|
||||
isRepair: order.damage.isRepair,
|
||||
glassToReplace: renameGlassToReplaceAttributes(order.damage.glassToReplace),
|
||||
lineItemsOnOrder: getArrayOfAllLineItems(lineItemsToUse),
|
||||
lineItemsOnOrder: getArrayOfAllLineItemsAndChildParts(lineItemsToUse),
|
||||
parentAccountNumber: useDefaultCashParentAccount
|
||||
? applicationConfig.CASH_PARENT_ACCOUNT_NUMBER
|
||||
: order.payment.parentAccountNumber,
|
||||
|
|
@ -2941,7 +2941,9 @@ export const actions = {
|
|||
|
||||
async getRecalPartsAndSaveToLineItems(context, { pageNameToLog }) {
|
||||
// identify each part that needs recal
|
||||
const glassParts = context.state.order?.lineItems?.glassParts ?? [];
|
||||
const glassParts = context.state.order?.lineItems?.glassParts
|
||||
? deepClone(context.state.order.lineItems.glassParts)
|
||||
: [];
|
||||
|
||||
for (let i = 0; i < glassParts.length; i++) {
|
||||
// does this part need recal?
|
||||
|
|
@ -2974,6 +2976,7 @@ export const actions = {
|
|||
}
|
||||
|
||||
glassParts[i].childParts.push(...recalPartResponse.data.recalibrationParts);
|
||||
context.dispatch(storeActions.SAVE_GLASS_PARTS, glassParts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3168,20 +3171,32 @@ export function mapTaxedLineItemsToStoreFormat(availableLineItems, storeLineItem
|
|||
return lineItems;
|
||||
}
|
||||
|
||||
export function getArrayOfAllLineItems(lineItems) {
|
||||
export function getArrayOfAllLineItemsAndChildParts(lineItems) {
|
||||
let consolidatedLineItemsArray = [];
|
||||
|
||||
if (lineItems.glassParts != null)
|
||||
consolidatedLineItemsArray = [...consolidatedLineItemsArray, ...lineItems.glassParts];
|
||||
consolidatedLineItemsArray = [
|
||||
...consolidatedLineItemsArray,
|
||||
...getFlattenedArrayOfLineItemsWithChildParts(lineItems.glassParts),
|
||||
];
|
||||
|
||||
if (lineItems.supportingItems != null)
|
||||
consolidatedLineItemsArray = [...consolidatedLineItemsArray, ...lineItems.supportingItems];
|
||||
consolidatedLineItemsArray = [
|
||||
...consolidatedLineItemsArray,
|
||||
...getFlattenedArrayOfLineItemsWithChildParts(lineItems.supportingItems),
|
||||
];
|
||||
|
||||
if (lineItems.vaps != null)
|
||||
consolidatedLineItemsArray = [...consolidatedLineItemsArray, ...lineItems.vaps];
|
||||
consolidatedLineItemsArray = [
|
||||
...consolidatedLineItemsArray,
|
||||
...getFlattenedArrayOfLineItemsWithChildParts(lineItems.vaps),
|
||||
];
|
||||
|
||||
if (lineItems.promos != null)
|
||||
consolidatedLineItemsArray = [...consolidatedLineItemsArray, ...lineItems.promos];
|
||||
consolidatedLineItemsArray = [
|
||||
...consolidatedLineItemsArray,
|
||||
...getFlattenedArrayOfLineItemsWithChildParts(lineItems.promos),
|
||||
];
|
||||
|
||||
return consolidatedLineItemsArray;
|
||||
}
|
||||
|
|
@ -3260,6 +3275,9 @@ function addGuidToLineItemsIfNotAlreadyThere(lineItems) {
|
|||
if (!lineItem.id) {
|
||||
lineItem.id = crypto.randomUUID();
|
||||
}
|
||||
if (lineItem.childParts) {
|
||||
addGuidToLineItemsIfNotAlreadyThere(lineItem.childParts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue