add vaps to lineitems

add vaps to lineitems
This commit is contained in:
hiteshkumar87 2023-11-09 18:03:45 +05:30
parent b7f46e877f
commit 84c7e8c617
2 changed files with 34 additions and 34 deletions

View file

@ -16,8 +16,8 @@
customInputId="promoCode"
v-model="promoCode"
cmsWidgetName="PromoQuestionWidget" />
<div v-for="(promos,i) in this.lineItems?.promos" :key="i">
<span class="applied-promo">Promo code "{{ promos }}" applied </span>
<div v-for="(promo, i) in this.getPromoList" :key="i">
<span class="applied-promo">Promo code "{{ promo[i].promoCode }}" applied </span>
<textLink
ref="removeLink"
linkType="text"
@ -43,8 +43,11 @@ import modal from "@/digital-components/modal/modal";
import alert from "@/ux-components/alert/alert";
import { deepClone } from "@/helpers/object-helper";
import { storeActions } from "@/constants/store-actions.js";
import { getVapsThatNeedToBeAddedToSatisfyPromos,getAddableVapsFromAvailableLineItems } from "@/helpers/promotions-helper";
import {
getVapsThatNeedToBeAddedToSatisfyPromos,
getAddableVapsFromAvailableLineItems,
} from "@/helpers/promotions-helper";
import baseMixin from "@/mixins/base-mixin.js";
export default {
name: "promo-modal-question",
@ -52,8 +55,7 @@ export default {
return {
promoCode: "",
promoTextInputId: "",
displayInvalidPromoAlert: false,
lineItems: deepClone(this.modelValue),
displayInvalidPromoAlert: false,
};
},
props: {
@ -83,7 +85,7 @@ export default {
return this.getCmsContent("AlertInvalidPromoWidget", "HeadlineText");
},
InvalidPromoText() {
return this.PromoText?.replaceAll("{custom:Promocode}", this.promoCode);
return this.PromoText?.replaceAll("{custom:PROMOCODE}", this.promoCode);
},
AddPromoSuccessMessageFromCms() {
return this.getCmsContent("PromoSuccessAlertWidget", "Text");
@ -91,6 +93,9 @@ export default {
removeLinkText() {
return this.getCmsContent("RemoveCartItemTextWidget", "Text");
},
getPromoList(){
return this.modelValue?.promos;
}
},
methods: {
resetAlerts() {
@ -113,19 +118,20 @@ export default {
this.modal.resetButtonStyle();
},
getPromoAddedMessage() {
return this.AddPromoSuccessMessageFromCms?.replaceAll("{custom}", this.promoCode);
return this.AddPromoSuccessMessageFromCms?.replaceAll("{custom:PROMOCODE}", this.promoCode);
},
async getPromoCodeData(promoCode, lineItems, availableLineItems, pageNameToLog = null) {
const pageName = pageNameToLog ?? this.$options?.name;
const addableVaps = getAddableVapsFromAvailableLineItems(availableLineItems);
const promoValidationResponse = await this.dispatchStoreActionWithLogging(
const lineItemsToUse = lineItems.Length > 0?lineItems:null;
const promoValidationResponse = await baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.VALIDATE_ORDER_PROMO_AND_SAVE_SERVER_DATA,
{
promoCode: promoCode,
lineItemsToUse: lineItems,
lineItemsToUse: lineItemsToUse,
addableVaps: addableVaps,
},
pageName
pageName,false
);
return {
@ -136,33 +142,27 @@ export default {
},
async addPromoCode() {
if (this.promoCode) {
this.resetAlerts();
// const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
// this.promoCode,
// this.availableLineItems,
// this.lineItems
// );
// this.lineItems.vaps?.push(getVaps);
this.resetAlerts();
const promoCodeData = await this.getPromoCodeData(
this.promoCode,
this.lineItems,
this.modelValue,
this.availableLineItems,
"payment-method"
);
if (promoCodeData.isValid) {
let promos = [];
promos.push(promoCodeData.promoCode);
const modelValue = this.modelValue;
modelValue.promos = promos;
this.closeModal();
// const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
// this.promoCode,
// this.availableLineItems,
// this.lineItems
// );
// this.lineItems.vaps?.push(getVaps);
const getVaps = getVapsThatNeedToBeAddedToSatisfyPromos(
promoCodeData.promoCode,
this.availableLineItems,
modelValue
);
modelValue.vaps?.push(...getVaps);
const message = this.getPromoAddedMessage();
this.$emit("added-to-cart", {
messageHeadline: "Promo Applied!",
@ -196,12 +196,12 @@ export default {
</script>
<style lang="scss" scoped>
.applied-promo {
padding-right: 7rem;
padding-right: 7rem;
font-family: Roboto;
font-size: 14px;
font-style: normal;
font-weight: 500;
line-height: 24px;
color:#0C7E47;
font-size: 14px;
font-style: normal;
font-weight: 500;
line-height: 24px;
color: #0c7e47;
}
</style>

View file

@ -25,7 +25,7 @@ defineRule("promo-required", required(errorMessages.PROMO_REQUIRED));
export default {
name: "promo-question",
props: {
modelValue:String,
modelValue: String,
cmsWidgetName: String,
},
computed: {