Our version of Spree does allow for multiple
shipments on each order, and each of these has its own
ShippingMethod, so in a lot of ways
order.shipping_method= behaves pretty much like an instance variable that is used to set the shipping method on the first shipment.
order.shipping_method probably shouldn’t be being used at all because it doesn’t mean anything (the shipping method on the first shipment can be changed, and this will not be reflected by
order.shipping_method). There is a convenience method
Order.shipment which just pulls up the most recent shipment. We have definitely abused
order.shipping_method a lot, but when it comes down to it, I think we can pretty much use
order.shipment.shipping_method (or equivalent) as a drop in replacement for
order.shipping_method. What do you think?
I didn’t even know that Spree had a
ShippingRate! It looks like it is just used for formatting of the rates in the checkout right? After having a look around in the OFN, I found that the rate for each shipping method for the current order is calculated in the shipping method serializer:
app/serializers/api/shipping_method_serializer.rb. This is made available to the angular on the checkout page, and is used to dynamically update the cost of delivery for the order based on the user’s selection. NOTE: This shipping rate is not submitted with the request, the shipping amount is recalculated on the server when the customer submits the order from the checkout.
My understanding of the way this happens is that the ‘cost’ for shipping is added to an order is via
adjustments. These use
calculators (defined by the shipping method) to determine the amount that should be charged for shipping (in the same way that the rates displayed to the customer are calculated). I’m not sure whether each shipment adds a new shipping adjustment to the order, or whether the total is just aggregated as one bulk shipping adjustment. I suspect it is the former, but I am not certain.
I’m not 100% clear on what the Spree 2.0 approach to this is, but to the best of my knowledge, we have not made any major changes to the existing system for calculating and applying the cost of shipping, so transitioning to the new approach will hopefully not be too crazy.
Does that help?