medusa
medusa copied to clipboard
Add address relation to cart retrieval in `FulfillmentService.calculatePrice`
Bug report
Describe the bug
When extending FulfillmentService, and the calculatePrice method is invoked, the cart param comes in without the shipping_address relationship.
This should be self explanatory, the shipping_address is required to get rate estimates from any third party.
As a result, we are forced to either retrieve the cart again with the relationship, or retrieve the address using the id
Either way, at this point in the flow, considering we already have the cart object, we shouldn't need to query for a shipping_address
Please add the shipping_address relationship when passing the cart to calculate_rate
System information
Medusa version 1.3.3 Node.js version: 16.15.1 Database: postgres 10.4 Operating system: Ubuntu 18.04 Browser (if relevant):
Steps to reproduce the behaviour
- Extend
FulfillmentService - Add items and shipping address to cart then
POST /store/carts/:id/shipping-methods - in extended
FulfillmentService -> canCalculateclassconsole.log(cart) - notice cart missing
shipping_addressrelationship
Expected behaviour
cart passed into canCalculate should have shipping_address relationship, otherwise it forces another db query to get the address
Hi there @macder! I completely understand your issue and why you've reported it. Though, I would not categorize this as a bug, since you can in fact achieve the functionality by injecting the cart service into your provider and re-fetch it with the required relations - as you mention in the description. The implementation specifics of different fulfillment providers vary quite a lot and we leave it to the plugins to handle the business logic that allows them to carry out the desired functionality.
Take our Stripe plugin as a different example. We do not pass the entire Customer object to the createPayment call even though it would clearly save us a DB operation. Again, this is due to the fact, that payment providers also vary quite a lot in regards to what they need in order for them to achieve the desired outcome.
That being said, I think it's reasonable to argue that calculatePrice and canCalculate in the fulfillment provider require the address to be present on the cart object. I'll tweak the label to be type: feature or enhancement and we'll include it in our product backlog. I hope you are cool with this!
Also, feel free to take a stab at it - would be super awesome! 😊
Hi @olivermrbl, That makes a lot of sense. Now that I have some more context, I'll agree that this is not a bug, but an enhancement worth looking into. I may try to take a stab at it.
Cheers
@macder - We are moving feature requests to GitHub Discussions to keep better track of the most requested features (using the upvote mechanism) and streamline GitHub Issues around bugs. Could I ask you to re-open your request here: https://github.com/medusajs/medusa/discussions/categories/feature-requests
Thanks!