HomeHome Product Discus... Product Discus...RazorCartRazorCartSurfacing a dialog on the checkout pageSurfacing a dialog on the checkout page
Previous
 
Next
New Post
5/21/2019 1:23 PM
 
Two questions:
One of our sites offers free shipping if the customer orders 30 or more items. What's the easiest way to set the (Custom) shipping method based on the quantity ordered? We could probably set the site for shipping by quantity, set the free-for-30 as the first and it only shows when there are 30 pieces.

But it runs into a problem when the customer changes quantities on the checkout page. I can probably check in a custom recalculate code to move it away from the free shipping if they were at 30 and change to drop below it, but when they were at 25 and go to 35...

We'd prefer to pop up a dialog that says "Your order now qualifies for free shipping. Would you like to switch shipping methods?" I've never had much luck surfacing dialogs from that code, especially a yes/no one, on the checkout page. How would you recommend to do it?

Thank you,
G

 
New Post
5/22/2019 5:54 PM
 
You can easily extend the pipeline action CalculateShipping and insert a free shipping method after you check the order qualification:
public override ActionEndResult Execute(VATContext context)
{
    var result = base.Execute(context);
    if (result.Success)
    {
        if (context.CartList.Sum(i => i.Quantity) > 30)
        {
            context.ShippingMethods.Add(new ShippingMethod() { Code = "Free-30", Price = 0M, Text = "Free Shipping" });
            ShippingMethod selectedMethod = context.ShippingMethods.FirstOrDefault(m => m.Code == context.ShippingData.Method);
            if (selectedMethod != null)
            {
                context.CartTotals.ShippingTotal = selectedMethod.Price.HasValue ? selectedMethod.Price.Value : 0M;
            }
            else
            {
                selectedMethod = context.ShippingMethods.FirstOrDefault();
                context.ShippingData.Method = selectedMethod.Code;
                context.CartTotals.ShippingTotal = selectedMethod.Price.HasValue ? selectedMethod.Price.Value : 0M;
            }
        }
        return new ActionEndResult() { Success = true, FailureMessage = string.Empty };
    }
    else
    {
        return new ActionEndResult() { Success = false, FailureMessage = result.FailureMessage };
    }
}

For the user notification popup I prefer you modify the view file to inject an AngularJS scope $watch for the controller property "shippingMethods" (vm.shippingMethods) to open the popup when the method code "Free-30" found. Check this old post answer for doing a similar scenario: https://www.smith-consulting.com/Foru...693/scope/posts
 
Previous
 
Next
HomeHome Product Discus... Product Discus...RazorCartRazorCartSurfacing a dialog on the checkout pageSurfacing a dialog on the checkout page