Posted on 22/12/2023 12:23:43
Hi Caro
In Swift/Components/EcommerceBadge.cshtml you have the below code - I added some very untested code, but it will get you the name of the (first) discount applied - there can be many, and this one will take the first. You might want to add more logic to when to override the badge name and add additional null checks
@if (Model.Discount.Price != 0)
{
string saleBadgeCssClassName = GetViewParameter("saleBadgeCssClassName") != null ? GetViewParameterString("saleBadgeCssClassName").Trim().ToLower() : "";
bool saleBadgeEnabled = saleBadgeCssClassName != "" && saleBadgeCssClassName != "none" ? true : false;
if (saleBadgeEnabled)
{
string saleBadgeType = GetViewParameter("saleBadgeType") != null ? GetViewParameterString("saleBadgeType") : "amount";
string title = saleBadgeType == "amount" ? "-" + Model.Discount.PriceFormatted : "";
title = saleBadgeType == "percentage" ? "-" + Math.Round((Model.Discount.Price / Model.PriceBeforeDiscount.Price) * 100) + "%" : title;
var discountName = Model.ProductDiscounts.First().Name;
title = discountName;
string hideAutoLabel = "";
if (saleBadgeType == "amount" || saleBadgeType == "percentage")
{
hideAutoLabel = "badge-no-label";
}
<span class="@sizeCssClass"><span class="badge @hideAutoLabel @(saleBadgeCssClassName) rounded-0">@title</span></span>
}
}