Index: uc_location.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_location/uc_location.module,v
retrieving revision 1.2
diff -u -p -r1.2 uc_location.module
--- uc_location.module	6 Oct 2009 22:12:31 -0000	1.2
+++ uc_location.module	9 Oct 2009 11:13:43 -0000
@@ -72,31 +72,29 @@ function uc_location_form_uc_cart_checko
   global $user;
   
   $is_billable = !empty($form['panes']['billing']);
-  $is_deliverable = !empty($form['panes']['delivery']);
-  $is_shippable =  (uc_cart_is_shippable() || !variable_get('uc_cart_delivery_not_shippable', TRUE));
+  $is_deliverable = !empty($form['panes']['delivery']) && (uc_cart_is_shippable() || !variable_get('uc_cart_delivery_not_shippable', TRUE));
 
   // If new user, remove the address selection fields.
   if ($user->uid == 0) {
     unset($form['panes']['delivery']['delivery_address_select']);
     unset($form['panes']['billing']['billing_address_select']);
   } 
-  else { 
-    // Recreate address selection field(s) for billing and/or delivery.
-    
-    if ($is_billable || ($is_shippable && $is_deliverable) && !empty($user->locations) ) {
-      drupal_add_js(drupal_get_path('module', 'uc_location') .'/uc_location.js');
-      
-      // Create book icon and address list.
-      $address_book_icon = l(uc_store_get_icon('file:address_book', FALSE, 'address-book-icon'), 
+  elseif (($is_billable || $is_deliverable) && $address_list = _uc_location_create_address_list()) {
+    drupal_add_js(drupal_get_path('module', 'uc_location') .'/uc_location.js');
+
+    if (user_access('set own user location')) {
+      $address_book_icon = l(uc_store_get_icon('file:address_book', FALSE, 'address-book-icon'),
         'user/'. $user->uid .'/edit', array('html' => TRUE));
-      $address_list = _uc_location_create_address_list();
     }
-    
+    else {
+      $address_book_icon = '';
+    }
+
     if ($is_billable) {
       _uc_location_recreate_address_select_field(
         $form['panes']['billing'], 'billing', $address_list, $address_book_icon);
     }
-    if ($is_shippable && $is_deliverable) {
+    if ($is_deliverable) {
       _uc_location_recreate_address_select_field(
         $form['panes']['delivery'], 'delivery', $address_list, $address_book_icon);
     } 
@@ -155,7 +153,9 @@ function uc_location_save_location(&$ord
 function _uc_location_create_address_list() {
   global $user; 
   
-  if (!isset($user->locations)) {
+  // Reload user account as the locations are not always loaded.
+  $account = user_load($user->uid);
+  if (!isset($account->locations)) {
     // Not acceptable.
     // Note that this module has the "location" module as a dependency, 
     // so this probably should never get here.
@@ -168,7 +168,7 @@ function _uc_location_create_address_lis
   
   $address_list = array('0' => t('Select one...'));
   
-  foreach ($user->locations as $location) {
+  foreach ($account->locations as $location) {
     $uc_address = _uc_location_to_uc_address($location);
   
     if ($location['name']) {
@@ -235,7 +235,7 @@ function _uc_location_to_uc_address(&$lo
   $address['zone'] = $location['province_name'];
   $address['postal_code'] = $location['postal_code'];
   $address['country'] = $location['country_name'];
-  $address['phone'] = $location['phone'];
+  $address['phone'] = isset($location['phone']) ? $location['phone'] : '';
   
   return $address;
 }
