I'm trying to show the delivery time for each ship...
# support
u
I'm trying to show the delivery time for each shipping method. I found this guide https://guides.solidus.io/advanced-solidus/stock-and-fulfillment/#shipping-rate-selector, but I not understood the comment that say "This assumes
Spree::ShippingRate
responds to `#delivery_time`", delivery_time its a method that I have to implement? Or have another way to show the delivery time in Delivery step?
k
Yes, it’s only one example of how you could customize it based on your logic. But you made a point, it’s not clear that that specific method is the custom part of it.
u
Got it. Thanks. Just to double check if my understanding is correct: Solidus by default does not implement a way to save/display delivery times, so I should add this custom logic myself. Would then, a reasonable implementation be to generate a migration that adds a delivery_time column to Spree::ShippingRate and override the calculate_shipping_rates method from Spree:Stock:Estimator to also fill in the values for the added column?
k
yes, or request that information to some API if your service of choice has that information
u
We use a popular shipping service here in Brazil called Melhor Envio, so to get the shipping costs from their api, we had already implemented a shipping calculator and configured it in the initializer: config.environment.calculators.shipping_methods << 'Spree:CalculatorShipping:MelhorEnvio' This is were we are firing off the api requests to Melhor Envio and getting the estimated shipping costs back, that we return in our implementation of compute_package. If there is a more adequate place to put the api calls, please suggest it. We want our implementation to be as in line with the Solidus way as possible. To get the delivery time estimate displayed to the customer, we have also implemented a compute_package_delivery_time method that (currently) repeats the api call and returns the delivery time. So then our overridden calculate_shipping_rates method from Spree:Stock:Estimator calls compute_package and, if the shipping method responds to compute_package_delivery_time, calls it as well and fills in the delivery_time column for that ShippingRate.
k
Seems a good approach. Out of curiosity, can’t you get the delivery time in the first call (to get the shipping cost) and save it on the rate at that time, so you can avoid the second API call?
u
I found a way to make only one request to get this. Thanks for the help!
🎉 1