Hi

First of all, this module is amazing by the way it integrates with ubercart module checkout process.

However, I have some specific requirements.
1) Instead of user creating new addresses automatically, I would like to have two separate addresses (Shipping/Billing) separately even if they are same. Right now, it generates error if two addresses are same.
2) Also, I would like to show these address fields editable on user profile edit page rather than a separate tab.

I guess I will need to write some PHP code for this. I do not want to hack the module so look forward for some guidance. Please let me know your thoughts. Thanks.

Comments

There is one more request. I would also like to change the sequence of fields inside address like Phone Number shall be at the end of address.

Thank you so much.

Category:feature» support

1) Creating duplicate addresses: The address book API doesn't have explicit restrictions to create duplicate addresses. It has a method called compareAddress(), but it's not called upon address saving. You can achieve duplicate addresses by saving them programmatically. For the address form in the address book, you could also overwrite the form validate function uc_addresses_get_address_form_validate() using a form alter to skip the check for duplicate addresses.
Keep in mind that the API doesn't allow two addresses with the same nickname.

2) Address book on profile edit page: This should be done with custom code. You could implement the hook hook_menu_alter() to remove access to paths starting with user/%user_uid_optional/addresses. Keep in mind that if you do that, links to addresses from elsewhere may no longer work, such as in Views (coming in the next release, see #1900176: Views integration: address view, edit and delete links).

3) Change the order of address fields in forms: Extra Fields Pane 6.x-2.x has a feature for that. For the Drupal 7 version, this feature was implemented in Ubercart core.

See The developer's guide to Ubercart Addresses for more information about Ubercart Addresses' API's.

Thanks MegaChriz. I will look into this information. Will let you know if I face any issues.

Megachriz,

I think I have not been clear OR I am not able to understand what you wrote.

Right now, there is option to provide user with one address field (the default address) on registration. This default address is used for both default billing address and default shipping address.
What I would like is:
To provide user with fields for two default addresses, one for Default Shipping Address and one for Default Billing Address on "Regitration" page itself.

Is there any way to achieve this?

Okay, so you would like to have fields for two addresses on the registration page (user/register)? I had assumed first you'd like to have an address edit form on the user profile edit page (user/%user/edit).
There is already a feature request about registering with two addresses: #1089796: Is it possible to have two address fields setup when a user registers?. At this moment, it's not possible to ask for two addresses (for Ubercart Addresses) at registration without custom code. Do you want to help with getting this feature in? You don't have to be coder to help. You can also help by:

  • Describing how you would like this feature to work. Think about both the user registration page and the Ubercart Addresses settings page. For example, how should the settings page be designed so admins can choose if on the registration page customers should provide one or two addresses? Think also about how the settings page should look like when admins decide to disable default shipping addresses, for example.
  • Creating a graphical representation of the user interface (again, both the user registration page and the Ubercart Addresses settings page).

Were your other questions answered?

Thanks MegaChriz for your response.

I wanted to have this functionality right now. So I have made fields using Profile module and then wrote custom module. Custom module adds records of user register form and user profile edit form in the uc_addresses table.

However, I am having few things to tackle:
1) I could see that countries and states/province are stored in the form of country code and zone codes.
2) Address gets validated for postal code etc.

I would like to know if I can use some hooks to country and state dropdown in the fields added by Profile module which can give country and zone code as values.

I know what I am going to write next is not concerned with uc_addresses but still I would ask hoping to get a solution. I was trying to edit the options present in country field by writing following code:

<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if((
$form_id == 'user-register') || ($form_id == 'profile_form_profile')) {
   
$form['profile_billing_country']['#options'] = array('840' => t('United States'), '124' => t('Canada'));
  }
  return
$form;
}
?>

I even tried using #after_build of form using following code:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if(($form_id == 'user-register') || ($form_id == 'profile_form_profile')) {
    $form['profile_billing_country']['#options'] = array('840' => t('United States'), '124' => t('Canada'));
    $form['#after_build'][] = 'mymodule_after_build';
  }
  return $form;
}
function mymodule_after_build($form, &$form_state) {
  $form['profile_billing_country']['#options'] = array('840' => t('United States'), '124' => t('Canada'));
  return $form;
}
?>

but even this is not working. Though it is concerned with profile module OR form API but still thinking you might help. :)

I believe for country codes and zone codes, I will pull the list from the tables uc_countries and uc_codes respectively. Right?

Please let me know which function I shall use in the hook_user with op as validate to see if address fields are fine.

Thank you so much for your help.

And for flow you asked I don't think I might be of much help but yes I can help with custom coding if required. Please let me know if I can contribute back in uc_addresses.

I would like to know if I can use some hooks to country and state dropdown in the fields added by Profile module which can give country and zone code as values.
(...)
I believe for country codes and zone codes, I will pull the list from the tables uc_countries and uc_codes respectively. Right?

Countries are stored in the uc_countries table and zones in the uc_zones table. If you want to create select fields for them manually, you should query these tables. You can take a look in uc_addresses/handlers/ubercart.handlers.inc for an example on how the uc_addresses module populates the country and zone fields. Keep in mind that it can be hard to update the zone field when an other country is chosen: I got a lot of "illegal choice" errors in the beginning of developing uc_addresses 6.x-2.x.

I have made fields using Profile module and then wrote custom module. Custom module adds records of user register form and user profile edit form in the uc_addresses table.

While it's possible to use the Profile module to create the fields, I think it will be a lot easier to use a form alter hook and create a field of type "uc_addresses_address". After the form build, it will contain a collection of address fields. See also the documentation about the form element "uc_addresses_address".
You could also look at Ubercart Addresses' implementation of hook_user: uc_addresses_user().

Address gets validated for postal code etc.

You could add a validation callback function when doing a form alter. If the validation should happen for all forms where an address element is used, you could also implement hook_uc_addresses_address_field_alter() to add a validation callback in there:

<?php
/**
* Implements hook_uc_addresses_address_field_alter().
*/
function mymodule_uc_addresses_address_field_alter(&$element) {
 
// Add extra validation for all address forms.
 
$element['#element_validate'][] = 'mymodule_uc_addresses_address_validate';
}
?>

And for flow you asked I don't think I might be of much help but yes I can help with custom coding if required. Please let me know if I can contribute back in uc_addresses.

Great you consider to contribute back! :)
If you are not sure about the design of the admin page, you could also try to get two address forms on the register page with the possibility for the customer to say that the second address is equal to the first address, maybe in the form of a checkbox (just like on the checkout page). If you manage to do that, you could also try to have one saved as the default billing address and the other as the default shipping address. If the customer said the addresses are equal, only one address record should be created. Preferably, use the Ubercart Addresses API's as much as possible (and ask when something is unclear).

Status:Active» Fixed

I suppose your initial question has been answered. The feature for two address forms on the user registration page can be discussed further in #1089796: Is it possible to have two address fields setup when a user registers?.

Status:Fixed» Closed (fixed)

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