From e68033e18fc8ab31cc1658118c8cfdf657a51ef2 Mon Sep 17 00:00:00 2001
From: Capi Etheriel <barraponto@gmail.com>
Date: Mon, 20 May 2013 11:18:23 -0300
Subject: [PATCH] Issue #1370874 by barraponto: display estimated shipping
 times during checkout.

---
 commerce_correios.module |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/commerce_correios.module b/commerce_correios.module
index 6ef22e2..e7474d6 100644
--- a/commerce_correios.module
+++ b/commerce_correios.module
@@ -113,7 +113,7 @@ function commerce_correios_rate($shipping_service, $order) {
     $result = array(
       'amount' => commerce_currency_decimal_to_amount(str_replace(',', '.', (string) $rate->Valor), 'BRL'),
       'currency_code' => 'BRL',
-      'data' => array(),
+      'data' => array('delivery_estimates' => (string) $rate->PrazoEntrega),
     );
     return $result;
   }
@@ -149,6 +149,19 @@ function commerce_correios_rate($shipping_service, $order) {
 }
 
 /**
+ * Implements hook_commerce_shipping_line_item_new_alter().
+ */
+function commerce_correios_commerce_shipping_line_item_new_alter($line_item) {
+  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+  $commerce_correios_services = array_keys(commerce_shipping_services('correios'));
+  if (in_array($line_item_wrapper->commerce_shipping_service->value(), $commerce_correios_services)) {
+    $rate = $line_item_wrapper->commerce_unit_price->value();
+    $delivery_message = ': ' . format_plural($rate['data']['delivery_estimates'], '1 business day', '@count business days');
+    $line_item->data['shipping_service']['display_title'] .= $delivery_message;
+  }
+}
+
+/**
  * Get standardized package dimensions. Use Commerce Physical data if available.
  */
 function commerce_correios_package($order) {
-- 
1.7.9.5

