We have a case where we need to put the arrival estimative and price on the shipping service name that is shown on the checkout pane, like "My shipping service: 1 business day: $15.00", and a good approach could be to have a "display_title_callback" argument on hook_commerce_shipping_service_info(). Looking at the module code, looks that a patch on commerce_shipping_services function(http://api.drupalcommerce.org/api/Drupal%20Commerce/sites%21all%21module...) could add this.
Which way would be the best to address this question?
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | commerce_shipping-customize_display_title_for_shipping_services-1992734-3.patch | 1.05 KB | barraponto |
Comments
Comment #1
pedrorocha commentedLooking deeper, i think that the place to change is the function commerce_shipping_service_rate_options($order). As i don't know the module code as a whole, i don't know yet if the only place to change is this one.
Comment #2
barrapontoI think
hook_commerce_shipping_service_options_altershould be enough to implement this. Of course, it could be made more friendly to data operations, like adding estimated time. I think it should at least take an array of strings and then implode them with a customizable separator. Because right now I have to assume what is the separator (usually:) before manipulating the data. Not to mention the custom text from user-generated flat rate services that brings unpredictable strings to the table :PComment #3
barrapontoSo, it seems
shipping serviceandpriceis still available as data at the timehook_commerce_shipping_line_item_new_alteris called. But unfortunately,commerce_shipping_service_rate_optionswill ignore$line_item->databy callingcommerce_shipping_service_get_titlewhich loads from straight fromcommerce_shipping_service_info. The fix is already in the current code: usecommerce_shipping_line_item_titlewhich considers$line_item->data, falls back tohook_shipping_service_infodefinitions and finally falls back to eventual custom$line_item->line_item_label.Since we already have a
$line_itemincommerce_shipping_service_rate_options, this change is swift.Comment #4
barrapontoHere's an example of adding shipping delivery estimates to the display title, made possible thanks to this patch: #1370874-5: Shipping Time.
Comment #5
Byfred commentedI've tested and the barraponto's patch worked just fine
Comment #6
googletorp commentedLooks good, sorry for the long wait time.
Committed to dev.
Comment #7
googletorp commentedForgot status update.