top of page

Campaign

Introduction

The goal of this use case is to apply a promotion to a product option. According to type of promotion (Discount, Fixed amount or freely month). Here we have 2 cases.

The first one is apply a promotion according to a product option . If the promotion code is valid, you can use it to have a reduction in your production. However, how can you apply the promotion for the each product concerned.

First use case

Here you have one promotion for one product.

Tips: if you want for a subscription, activate your subscription


Custom object







In other object

Quote:


Quote line:






When you have all these metadatas, you can use this custom script



export function onBeforeCalculate(quoteModel, quoteLineModels, conn) {
applyPromo(quoteModel, quoteLineModels, conn);
return Promise.resolve();
}

function applyPromo(quoteModel, quoteLineModels, conn) {
if (quoteLineModels.length > 0 && !quoteModel.record["CampaignPromotion__c"]) {
quoteLineModels.forEach(function (l) {
if (l.record["SBQQ__Product__c"]) {
l.record["SBQQ__SpecialPrice__c"] = l.record["SBQQ__Listrice__c"];
l.record["SBQQ__SpecialPriceType__c"] = "";
l.record["CampaignType__c"] = "";
l.record["Promotion__c"] = null;
l.record["PromotionFreeMonths__c"] = 0;
}
});
}

else if (quoteLineModels.length > 0 && quoteModel.record["CampaignPromotion__c"]) {
let promotion = quoteModel.record["CampaignPromotion__c"];
return conn.query("Select Id,ProductOptionCampaign__c,PromotionType__c,Name, PromoFreeMonths__c,PromoDiscount__c,PromoAmount__c from Campaign__c where Active__c = true and Id='"+quoteModel.record['CampaignPromotion__c']+"'").then(function (results) {
if (results.totalSize) {
console.log("query non vide");
results.records.forEach((promotionAction) => {
quoteLineModels.forEach(function (line) {
line.record["SBQQ__SpecialPrice__c"] = line.record["SBQQ__Listrice__c"];
line.record["SBQQ__SpecialPriceType__c"] = "";
line.record["SBQQ__SpecialPriceDescription__c"] = "";
line.record["Promotion__c"] = null;
line.record["CampaignType__c"] = "";
line.record["PromotionFreeMonths__c"] = 0;
if (line.record["SBQQ__ProductOption__c"] == promotionAction["ProductOptionCampaign__c"]) {
if (promotionAction.PromotionType__c === "Free Months") {
console.log("promotion free months trouvé");
line.record["CampaignType__c"] = "Free Months";
line.record["PromotionFreeMonths__c"] = promotionAction.PromoFreeMonths__c;
line.record["Promotion__c"] = promotionAction.Id;
console.log('log promotion free months '+line.record["Promotion__c"]);
}
else if (promotionAction.PromotionType__c === "Amount") {
console.log("promotion amount trouvé");
line.record["CampaignType__c"] = "Amount";
line.record["Promotion__c"] = promotionAction.Id;
line.record["SBQQ__SpecialPrice__c"] = Number(line.record["SBQQ__ListPrice__c"]) - Number(promotionAction.PromoAmount__c);
line.record["SBQQ__SpecialPriceDescription__c"] = promotionAction.Name + " Promotion Applied type Amount for " + promotionAction.PromoAmount__c + " EUR";
line.record["SBQQ__SpecialPriceType__c"] = "Custom";
console.log('log promotion amount '+line.record["Promotion__c"]);
}
else if (promotionAction.PromotionType__c === "Percentage") {
console.log("promotion discount trouvé");
line.record["CampaignType__c"] = "Discount";
line.record["Promotion__c"] = promotionAction.Id;
line.record["SBQQ__SpecialPrice__c"] = line.record["SBQQ__ListPrice__c"] - (line.record["SBQQ__ListPrice__c"] * (promotionAction.PromoDiscount__c / 100));
line.record["SBQQ__SpecialPriceDescription__c"] = promotionAction.Name + " Promotion Applied of type Discount for " + promotionAction.PromoDiscount__c + " %";
line.record["SBQQ__SpecialPriceType__c"] = "Custom";
console.log('log promotion percentage '+line.record["Promotion__c"]);
}
}
});
});
}
});
}

}


Result


Second use case

Promotion




Promotion Action





Quote



Quote line:






Custom script



export function onBeforeCalculate(quoteModel, quoteLineModels, conn) {
applyPromo(quoteModel, quoteLineModels, conn);
return Promise.resolve();
}

function applyPromo(quoteModel, quoteLineModels, conn) {
if (quoteLineModels.length > 0 && !quoteModel.record["Promotion__c"]) {
quoteLineModels.forEach(function(l) {
if ( l.record["SBQQ__Product__c"] ) {
l.record["SBQQ__SpecialPrice__c"] = l.record["SBQQ__Listrice__c"];
l.record["SBQQ__SpecialPriceType__c"] = "";
l.record["PromotionType__c"] = "";
l.record["PromotionObject__c"] = null;
l.record["PromotionActionObject__c"] = null;
l.record["PromotionMonthsFree__c"] = 0;
}
});
}

else if (quoteLineModels.length > 0 && quoteModel.record["Promotion__c"]) {
let promotion = quoteModel.record["Promotion__c"];
return conn.query("select Id,ProductOption__c,PromotionType__c,Promotion__c,PromoFreeMonths__c,Promotion__r.Name,PromoDiscount__c,PromoAmount__c from PromotionAction__c where Promotion__r.Active__c =true and Promotion__c ='" + promotion + "'").then(function (results) {
if (results.totalSize) {
results.records.forEach(function (promotionAction) {
quoteLineModels.forEach(function (line) {
if (line.record["SBQQ__ProductOption__c"] == promotionAction["ProductOption__c"]) {

if (promotionAction.PromotionType__c === "Free Months") {
line.record["PromotionType__c"] = "Free Months";
line.record["PromotionMonthsFree__c"] = promotionAction.PromoFreeMonths__c;
line.record["PromotionObject__c"] = promotionAction.Promotion__c;
line.record["PromotionActionObject__c"] = promotionAction.Id;
}
else if (promotionAction.PromotionType__c === "Amount") {
line.record["PromotionType__c"] = "Amount";
line.record["PromotionObject__c"] = promotionAction.Promotion__c;
line.record["PromotionActionObject__c"] = promotionAction.Id;
line.record["SBQQ__SpecialPrice__c"] = Number(line.record["SBQQ__ListPrice__c"]) - Number(promotionAction.PromoAmount__c);
line.record["SBQQ__SpecialPriceDescription__c"] = promotionAction.Promotion__r.Name + " Promotion Applied type Amount for "+promotionAction.PromoAmount__c +" EUR";
line.record["SBQQ__SpecialPriceType__c"] = "Custom";
}
else if (promotionAction.PromotionType__c === "Percentage") {
line.record["PromotionType__c"] = "Discount";
line.record["PromotionObject__c"] = promotionAction.Promotion__c;
line.record["PromotionActionObject__c"] = promotionAction.Id;
line.record["SBQQ__SpecialPrice__c"] = line.record["SBQQ__ListPrice__c"] - (line.record["SBQQ__ListPrice__c"] * (promotionAction.PromoDiscount__c / 100));
line.record["SBQQ__SpecialPriceDescription__c"] = promotionAction.Promotion__r.Name + " Promotion Applied of type Discount for "+promotionAction.PromoDiscount__c +" %";
line.record["SBQQ__SpecialPriceType__c"] = "Custom";
}
}
});

});
}
// Clear the fields for each quote line
quoteLineModels.forEach(function(line) {
if( line.record["PromotionObject__c"] != promotion){
line.record["PromotionType__c"] = "";
line.record["PromotionObject__c"] = null;
line.record["PromotionActionObject__c"] = null;
line.record["PromotionMonthsFree__c"] = 0;
line.record["SBQQ__SpecialPrice__c"] = line.record["SBQQ__ListPrice__c"];
line.record["SBQQ__SpecialPriceType__c"] = "";
}
});
});
}

}

Result


Conclusion

With this, you are able to apply promotion to product option

0 views0 comments

Recent Posts

See All

Comentários

Avaliado com 0 de 5 estrelas.
Ainda sem avaliações

Adicione uma avaliação
bottom of page