Free shipping behavior

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 年 前
Hi,

I would separate the free shipping price adjustment behavior to facilitate other implementations (in my case I don't set all shipping options at 0$ when free shipping is on, I create a new shipping option with 0$ fee based on the cheapest shipping option for description, delivery date and other details.
11 年 前
Hi Alexandre,

Is it suggestion or are you asking for an advice on how to achieve it with less code changes?
11 年 前
It is a suggestion. I would normally add the free shipping option in the IShippingService.GetShippingOptions and override the IOrderTotalCalculationService.AdjustShippingRate to remove this part:


if (IsFreeShipping(cart))
    return decimal.Zero;


but to check if the cart applies for free shipping I need the IOrderTotalCalculationService which in turn needs the IShippingService. That's why I'm currently adding it in the controller. As for the AdjustShippingRate, right now I'm just commenting out the code above to keep in sync with eventual changes to the rest of this method (if I call the base method I need to call IsFreeShipping two times - one extra time in my method to restore the shipping rate).

I'm thinking of a method ApplyFreeShipping(IList<ShippingOption>) on IOrderTotalCalculationService that would be called when the cart qualifies for free shipping.
11 年 前
Sorry. I'm not sure how it could be done and where exactly you suggest to move IsFreeShipping method. When and where should IsFreeShipping method be invoked in this case?
11 年 前
In the CheckoutController, once you get the shipping options, you could do:


if (_orderTotalCalculationService.IsFreeShipping(cart)
{
    _orderTotalCalculationService.ApplyFreeShipping(shippingOptions);
}


(or put that into a method on the service to limit the logic in the controller)

and then loop in the shipping options to create the model. I would also remove the call to IsFreeShipping in the AdjustShippingRate method. This method could receive a flag to know if the cart is free shipping and return immediately if its true and the rate is 0$ for a given shipping option.
11 年 前
Maybe we just need a general setting to enable/disable it.  e.g.
"If all cart items are marked Free Shipping then shipping rate is $0"

This would allow shipping plugins to deal with it differently if they wanted to (e.g. the suggested "only the lowest option should be free" when using external carrier shipping [UPS, FedEx, etc])
11 年 前
I'm not sure about managing it by plugin. I think the freeshipping behavior should be independent (I'm thinking about the case where multiple shipping providers are active). What do you think? Maybe the free shipping behaviors should be managed by plugins that would be called by the ApplyFreeShipping method described earlier. That would allow people to select which one is active without a single line of code. Moreover, they could easily be configurable.
11 年 前
I think it needs some investigation to implement good way. I've just created a work item here
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.