CSR-1393 | Fix the display/removal of bundle promo codes in modal
This commit is contained in:
parent
a73dfc604b
commit
5ff73cc095
2 changed files with 26 additions and 15 deletions
|
|
@ -305,18 +305,13 @@ export function createPromoErrorAlert(promoCode, errorCode = null, additionalInf
|
|||
return alert;
|
||||
}
|
||||
|
||||
// private methods
|
||||
function findLineItemsWithPartType(typeToFind, itemsToSearch) {
|
||||
const partTypeMatches = itemsToSearch?.filter(
|
||||
(lineItem) => lineItem.partType.toUpperCase() === typeToFind.toUpperCase()
|
||||
);
|
||||
return partTypeMatches;
|
||||
}
|
||||
|
||||
// returns a list of promo codes (string) only without duplicates or bundle identifiers
|
||||
// <promos> parameter must be an array of objects with a 'promoCode' field
|
||||
function getPromoCodesFromPromoObjectsWithoutDuplicates(promos) {
|
||||
export function getPromoCodesFromPromoObjectsWithoutDuplicates(promos) {
|
||||
const promoCodes = [];
|
||||
if (!promos) {
|
||||
return promoCodes;
|
||||
}
|
||||
promos.forEach((promo) => {
|
||||
const promoCodeToDisplay = getPromoCodeWithoutBundleIdentifier(promo.promoCode);
|
||||
if (!promoCodes.includes(promoCodeToDisplay)) {
|
||||
|
|
@ -326,3 +321,11 @@ function getPromoCodesFromPromoObjectsWithoutDuplicates(promos) {
|
|||
|
||||
return promoCodes;
|
||||
}
|
||||
|
||||
// private methods
|
||||
function findLineItemsWithPartType(typeToFind, itemsToSearch) {
|
||||
const partTypeMatches = itemsToSearch?.filter(
|
||||
(lineItem) => lineItem.partType.toUpperCase() === typeToFind.toUpperCase()
|
||||
);
|
||||
return partTypeMatches;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@
|
|||
cmsWidgetName="AlertInvalidPromoOnOrderWidget"
|
||||
alertClass="alert-danger"
|
||||
v-bind:isDismissible="true" />
|
||||
<div v-for="(promo, i) in this.getPromoList()" :key="i">
|
||||
<span class="applied-promo">Promo code "{{ promo.promoCode }}" applied </span>
|
||||
<div v-for="(promoCode, i) in this.getPromoCodeList()" :key="i">
|
||||
<span class="applied-promo">Promo code "{{ promoCode }}" applied </span>
|
||||
<textLink
|
||||
ref="removeLink"
|
||||
linkType="text"
|
||||
:text="removeLinkText"
|
||||
href="#!"
|
||||
@click-event="removeItem(promo.promoCode)" />
|
||||
@click-event="removeItem(promoCode)" />
|
||||
</div>
|
||||
</modal>
|
||||
</div>
|
||||
|
|
@ -56,6 +56,8 @@ import { storeActions } from "@/constants/store-actions.js";
|
|||
import {
|
||||
getVapsThatNeedToBeAddedToSatisfyPromos,
|
||||
promoErrorCodes,
|
||||
getPromoCodesFromPromoObjectsWithoutDuplicates,
|
||||
getPromoCodeWithoutBundleIdentifier,
|
||||
} from "@/helpers/promotions-helper";
|
||||
import { deepClone } from "@/helpers/object-helper";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
|
|
@ -122,8 +124,11 @@ export default {
|
|||
resetsOnPromoInput() {
|
||||
this.resetAlerts();
|
||||
},
|
||||
getPromoList() {
|
||||
return this.lineItems.promos;
|
||||
getPromoCodeList() {
|
||||
const promosToDisplay = getPromoCodesFromPromoObjectsWithoutDuplicates(
|
||||
this.lineItems.promos
|
||||
);
|
||||
return promosToDisplay;
|
||||
},
|
||||
getPromoCode() {
|
||||
return this.lineItems.promos?.[0].promoCode;
|
||||
|
|
@ -171,7 +176,10 @@ export default {
|
|||
removeItem(promo) {
|
||||
this.lineItems[cartItemCategories.PROMOS] = this.lineItems[
|
||||
cartItemCategories.PROMOS
|
||||
].filter((lineItemsToKeep) => lineItemsToKeep.promoCode != promo);
|
||||
].filter(
|
||||
(lineItemsToKeep) =>
|
||||
getPromoCodeWithoutBundleIdentifier(lineItemsToKeep.promoCode) != promo
|
||||
);
|
||||
},
|
||||
async addPromoCode() {
|
||||
if (this.promoCode) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue