diff --git a/handlers/ubercart.handlers.inc b/handlers/ubercart.handlers.inc index 95a64de..a7bec76 100644 --- a/handlers/ubercart.handlers.inc +++ b/handlers/ubercart.handlers.inc @@ -116,6 +116,15 @@ class UcAddressesUcZoneFieldHandler extends UcAddressesUcFieldHandler { $options = array(-1 => t('Not applicable')); } + if (empty($form['#key_prefix'])) { + // When no key prefix is set, use the address ID as part of the zone wrapper ID. + $zone_wrapper_id = 'uc-address' . $this->getAddress()->getId() . '-zone-wrapper'; + } + else { + // When a key prefix is set, make this part of the zone wrapper ID. + $zone_wrapper_id = 'uc-store-address-' . str_replace('_', '-', $form['#key_prefix']) . '-zone-wrapper'; + } + return array( $fieldName => array( '#type' => 'select', @@ -123,7 +132,7 @@ class UcAddressesUcZoneFieldHandler extends UcAddressesUcFieldHandler { '#required' => $this->isFieldRequired(), '#options' => $options, '#default_value' => $default, - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#empty_value' => 0, ), @@ -243,6 +252,15 @@ class UcAddressesUcCountryFieldHandler extends UcAddressesUcFieldHandler { $options[] = t('No countries found.'); } + if (empty($form['#key_prefix'])) { + // When no key prefix is set, use the address ID as part of the zone wrapper ID. + $zone_wrapper_id = 'uc-address' . $this->getAddress()->getId() . '-zone-wrapper'; + } + else { + // When a key prefix is set, make this part of the zone wrapper ID. + $zone_wrapper_id = 'uc-store-address-' . str_replace('_', '-', $form['#key_prefix']) . '-zone-wrapper'; + } + return array( $fieldName => array( '#type' => 'select', @@ -252,7 +270,7 @@ class UcAddressesUcCountryFieldHandler extends UcAddressesUcFieldHandler { '#default_value' => empty($default) ? uc_store_default_country() : $default, '#ajax' => array( 'callback' => 'uc_store_update_address_field_zones', - 'wrapper' => 'uc-address' . $this->getAddress()->getId() . '-zone-wrapper', + 'wrapper' => $zone_wrapper_id, 'progress' => array( 'type' => 'throbber', ), diff --git a/uc_addresses.install b/uc_addresses.install index caa7d54..b2e8625 100644 --- a/uc_addresses.install +++ b/uc_addresses.install @@ -148,6 +148,20 @@ function uc_addresses_install() { 'delete own addresses', ) ); + + // Increase the weight of uc_addresses relative to uc_quote by an + // addition of 1 so that uc_addresses module can unset the property + // set by uc_quote's form_alter. + $weight = db_select('system', 's') + ->fields('s', array('weight')) + ->condition('name', 'uc_quote', '=') + ->execute() + ->fetchField(); + db_update('system') + ->fields(array('weight' => $weight + 1)) + ->condition('name', 'uc_addresses', '=') + ->execute(); + drupal_set_message($t("Ubercart Addresses is installed. The authenticated user automatically was granted the permissions %view_own, %edit_own and %delete_own.", array('%view_own' => $t('view own addresses'), '%edit_own' => $t('add/edit own addresses'), '%delete_own' => $t('delete own addresses'))), 'status'); } @@ -305,3 +319,21 @@ function uc_addresses_update_7100() { } } } + +/** + * Increase the weight of uc_addresses relative + * to uc_quote by an addition of 1 so that + * uc_addresses module can unset the property + * set by uc_quote's form_alter. + */ +function uc_addresses_update_7101() { + $weight = db_select('system', 's') + ->fields('s', array('weight')) + ->condition('name', 'uc_quote', '=') + ->execute() + ->fetchField(); + db_update('system') + ->fields(array('weight' => $weight + 1)) + ->condition('name', 'uc_addresses', '=') + ->execute(); +} diff --git a/uc_addresses.module b/uc_addresses.module index 1b727a7..01d567d 100644 --- a/uc_addresses.module +++ b/uc_addresses.module @@ -926,6 +926,18 @@ function uc_addresses_form_user_register_form_submit(&$form, $form_state) { } /** + * Implements hook_form_FORM_ID_alter() for uc_cart_checkout_form(). + * + * Unsets '#process' key set by uc_quote module which overwrites + * the functionality of uc_addresses. + */ +function uc_addresses_form_uc_cart_checkout_form_alter(&$form, &$form_state) { + if (isset($form['panes']['delivery']['address'])) { + $form['panes']['delivery']['address']['#process'] = array('uc_addresses_process_address_field', 'uc_quote_process_checkout_address'); + } +} + +/** * Implements hook_form_FORM_ID_alter() for form uc_store_address_fields_form(). * * Adds address fields from Ubercart Addresses to the address field settings form,