How To (Ubercart): Get shipping quotes on the How To (Ubercart): Get shipping quotes on the

As you get your hands dirty with Ubercart you will find little things you don't like. Some of the little things are important and others are not. If you stick with Ubercart long enough you will learn that with time, skill, and determination you can modify your Ubercart install as your wish - most of the time.

Out of the box Ubercart comes with a shipping quote module that can estimate shipping costs between carriers. This module is responsible for pulling quotes on the cart/checkout page as well as the /cart page too. The one downside to this feature, the /cart page only supports a zip code field and nothing else. When trying to use shipping services like USPS and shipping Internationally, you will get errors from the USPS web service.

After digging around I found this can easily be fixed. Matter of fact I am surprised the solution or something like it is not available yet on Ubercart's website. Since this fix doesn't require a lot of effort I thought I would share it with others. Before I begin let me explain the shipping arrangement for this particular site where I implemented this solution.

The site is located in the USA and ships with UPS to the States and USPS to 29 other countries. There are three steps to make both of these shipping carriers work. Before continuing, I am assuming you have both the Ubercart shipping module enabled as well as the USPS and UPS modules.

The first thing to do is open up the following file: /ubercart/shipping/uc_quote.

Before:

<?php
$form
['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), '', true, NULL, 10, 10);
?>

Add the following:

<?php
$form
['delivery_country'] = uc_country_select(uc_get_field_name('country'), uc_store_default_country(), NULL, 'name', TRUE);
$country_id = isset($_POST['delivery_country']) ? intval($_POST['delivery_country']) : uc_store_default_country();
$form['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), null, null, $country_id, 'name', true);
?>

Next we need to override function theme_uc_cart_pane_quotes(). Instead of making this change in the uc_quote module, place the following in your theme template file (template.php):

<?php
function themename_uc_cart_pane_quotes($form) {
$output = '<div class="solid-border">';
$output .= '<h3>'. t('Calculate Shipping Cost:') .'</h3>';
$output .= drupal_render($form['delivery_country']);
$output .= drupal_render($form['delivery_zone']);
$output .= drupal_render($form['delivery_postal_code']);
$output .= drupal_render($form['get_quote']);
$output .= drupal_render($form);
$output .= '</div>';

return $output;
}
?>

If you are shipping to multiple countries and wish to use one carrier for one country and another carrier for other countries, you need to do one more step. Make some changes in the workflow-ng configurations for the shippers. This can be found at /admin/workflow-ng/configurations.

In my case I enabled the UPS rule and the USPS Intl rule. Now go into each rule and add a condition. For example, if you only want UPS to give quotes for the United States, then you would just select United States within the condition. Next, in the USPS Intl rule you would need to add a condition as well. This time choose the "Negate" checkbox and choose the United States or any other states you wish to NOT give a USPS Intl quote too.

Congratulations! Now you are ready to offer shipping quotes with multiple carriers to multiple countries.

Guest7654

11.03.2008

Thank you for sharing this solution. I am building a bookstore in Ubercart and although I am not going to ship from the United States, it's handy to have such solutions to guide you through tricky areas in Ubercart.

Guest13834

11.03.2008

That's a very interesting technique. Do you know how I could get a quote to work via flatrate module, so that a user chooses their delivery zone, and a quote is supplied? Currently it seems that the quote module only works via a postal code.

Guest13834

11.04.2008

I ended up overriding the function that supplies $form['delivery_postal_code'], instead supplying a select with postal codes mapped to delivery zones. When someone choose a zone, a postal code is sent off for a quote.

Ubercart webshop

08.12.2009

Hi, thanks for sharing. You did point out an important usability issue in Ubercart in my opinion. Hacking is totally against Drupal's dev philosophy (and mine), but he, user experience is king in e-commerce!

elvis

08.12.2009

The UC team ended up adding this in uc_shipping module.

Name
E-mail (Kept Private)
Your Website
CAPTCHA
Are you human?
Image CAPTCHA