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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pedrorocha’s picture

Looking 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.

barraponto’s picture

Status: Needs review » Active

I think hook_commerce_shipping_service_options_alter should 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 :P

barraponto’s picture

So, it seems shipping service and price is still available as data at the time hook_commerce_shipping_line_item_new_alter is called. But unfortunately, commerce_shipping_service_rate_options will ignore $line_item->data by calling commerce_shipping_service_get_title which loads from straight from commerce_shipping_service_info. The fix is already in the current code: use commerce_shipping_line_item_title which considers $line_item->data, falls back to hook_shipping_service_info definitions and finally falls back to eventual custom $line_item->line_item_label.

Since we already have a $line_item in commerce_shipping_service_rate_options, this change is swift.

barraponto’s picture

Status: Active » Needs review

Here's an example of adding shipping delivery estimates to the display title, made possible thanks to this patch: #1370874-5: Shipping Time.

Byfred’s picture

Status: Needs review » Reviewed & tested by the community

I've tested and the barraponto's patch worked just fine

googletorp’s picture

Looks good, sorry for the long wait time.

Committed to dev.

googletorp’s picture

Status: Reviewed & tested by the community » Fixed

Forgot status update.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.