Allow store add shipping method to cart API route to specify multiple shipping options #13215
NicolasGorga
started this conversation in
Feature Requests
Replies: 1 comment 4 replies
-
|
Thanks for sharing @NicolasGorga. And appreciate the level of detail. This is a good and perfectly valid suggestion. That said, I’m hesitant to introduce a breaking change to the existing API and workflow for this use case. It's relatively uncommon compared to adding a single method, and I believe we can find a way to support this through alternative approaches. Possible options could be:
This way, we can support the scenario without introducing a breaking change. I'd be happy to flesh these approaches out in detail with you, if we choose to go down this path. Curious to hear what you think. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently (v2.9.0) the /store/carts/[id]/shipping-methods route only allows a single shipping method to be added to the cart, both on the query validator StoreAddCartShippingMethods passed to validateAndTransformQuery, as well as in the object passed as input for the addShippingMethodToCartWorkflow.
A cart naturally can have more than one shipping method, for example when items coming from different StockLocations with different ShippingOptions are purchased from the same cart. The addShippingMethodToCartWorkflow allows for this, but internally, calls the removeShippingMethodFromCartStep for all the currently set shipping methods for the cart. If you are updating the cart shipping methods by interacting with this API core route, then you are effectively only being able to have one shipping method linked to a cart at any given moment.
I propose aligning the core API route to the signature of the addShippingMethodToCartWorkflow, allowing an array of shipping option ids, along with their data fields, to be passed to the endpoint and send this as is to the workflow. This will allow us to add multiple shipping options to a cart from the API core route in charge of this.
I could take on this, just would like the team input on this. Below my plan and observations:
Update sdk.store.cart.addShippingMethod, so the second argument reflects this change
This is a BREAKING CHANGE but i guess it is necessary if we don't want to cause confusion as to what should be passed in the body of the API route. I say this as i guesss to make it backward compatible then we could specify wither this new schema or the previous and handle how the input to the workflow should be constructed depending on which one it is.
Doc changes: The endpoint reference should be updated https://docs.medusajs.com/api/store#carts_postcartsidshippingmethods, i think i read once it was auto generated from comments in the route file? I am not so sure about this, but i don't see any in the current source code, so clarification here would be super.
Guide changes: Guides like this should also be changed: https://docs.medusajs.com/resources/storefront-development/checkout/shipping, specifically, the code snippets that interact with sdk.store.cart.addShippingMethod
Let me know what you think team!
Beta Was this translation helpful? Give feedback.
All reactions