SaaS CMS has officially launched! Learn more now.

Get amount missing for free shipping discount

Vote:
 

Hi,

We have "Spend for Free Shipping" discount set on out website and we want to show information how much money customer need to add to the cart to get free shipping. Is there a way to get this information using ICart object?

#321963
May 13, 2024 13:47
Vote:
 

Hi,

I don't think there's an easy, ready-to-use method which does exactly what you want but you could probably calculate the difference yourself by running the promotions engine against the cart, looking through all of the unfulfilled promotions for the free shipping promotion then looking at the minimum spend configured for that promotion in the current currency. A simple example might look something like this (though you'd probably want to inject the IPromotionEngine rather than using ServiceLocator):

var rewards = ServiceLocator.Current.GetInstance<IPromotionEngine>().Run(cart, new PromotionEngineSettings(RequestFulfillmentStatus.PartiallyFulfilled | RequestFulfillmentStatus.NotFulfilled, false));
foreach (var reward in rewards)
{
    if (reward.Promotion is EPiServer.Commerce.Marketing.Promotions.SpendAmountGetFreeShipping freeShippingPromotion)
    {
        var cartSubTotal = cart.GetSubTotal();
        var threshold = freeShippingPromotion.Condition.Amounts.FirstOrDefault(x => x.Currency == cart.Currency);
        if (threshold > 0)
        {
            var additionalSpendRequiredToGetDiscount = threshold - cartSubTotal;
        }
    }
}

One word of caution though - that's probably quite a resource intensive bit of code so I'd use it sparingly.

#321968
May 13, 2024 17:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.