Craft Commerce appears to set the shipping method for a cart to the last in the list of available methods, before a user has selected a shipping method or even entered an address.
shippingMethod shippingMethodHandle and shippingMethodId should all return null until a user selects a shipping method, correct?
In Commerce 2 we default the cart to the first available (cheapest) shipping method available.
See changelog item for 2.0.0: https://github.com/craftcms/commerce/blob/develop/CHANGELOG-v2.md#200---2019-01-15
I also find this a bit confusing. Once a user has entered their shipping address, but not yet chosen a shipping method, if I output cart.shippingMethod then it shows an instance of craft\commerce\models\ShippingMethod rather than an expected NULL.
If I view the relevant active cart in the CP it's not showing any shipping method as being chosen and the cart.totalPrice figure on the front-end doesn't yet include the cost of the shipping method shown in cart.shippingMethod.
I've built an Order Overview component on the front-end which is present at every step of the checkout process, and the logic in here only displays the shipping costs if cart.shippingMethod is not NULL. However, the way Craft Commerce currently works means it's displaying the shipping costs before they've actually been chosen and the cart.totalPrice figure also doesn't include these shipping costs.
@lukeholder The issue I'm having with this default is that we offer local pickup, which is always free so it always ends up being set as the default shipping method. While we want local pickup to be available as an option, I don't know that we want it selected by default. Do you know of a workaround for this?
It would be nice if there were a Commerce config setting that would revert to the Commerce 1 functionality that returns a null shipping method until selected. Or if it cannot be null, a config setting that lets you set a prioritized array of shipping method handles to define which shipping method to default to. Something like:
defaultShippingMethod => [
'standard',
'two-day'
]
In this scenario, the system would first search to see if the cart has standard shipping available and set it to that if available. If not, then it would see if two-day is available and set it to that. If not, then it would default to the system standard of whatever shipping method is cheapest. Would something like that even be feasible?
Running into this same issue. A user has the ability to enter their own shipping account info and bypass using any commerce shipping methods. Would love for some ability to _not_ set a default shipping method handle after adding their address.
+1 for this issue. We have the same problem where we offer collect from store (cost 拢0) but don't want that as the default option.
Instead of setting to the first available shipping method would it be a better solution to find all possible matches for valid shipping methods and if there is more than 1, then apply the first based on the order they appear in our shipping methods list? That way it would be possible to explicitly set a "default" option.
Most helpful comment
+1 for this issue. We have the same problem where we offer collect from store (cost 拢0) but don't want that as the default option.
Instead of setting to the first available shipping method would it be a better solution to find all possible matches for valid shipping methods and if there is more than 1, then apply the first based on the order they appear in our shipping methods list? That way it would be possible to explicitly set a "default" option.