Hi,

Please could you integrate this module with real name module? At the moment I am having to enter the customer name in two places, would be very useful to get rid of the profile fields. Using the default address as the real name fields.

I am very happy to pay to get this done quickly. I understand it can be done as per the real name documentation here: http://drupal.org/node/329662. Unfortunately I don't know php :(.

Thanks,
Paul.

CommentFileSizeAuthor
#2 realname_uc_addresses.zip3.23 KBMegaChriz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MegaChriz’s picture

Assigned: Unassigned » MegaChriz

Hi Paul,

That's looks like a nice addition to the module. I never used the RealName module myself as I thought it would work with profile fields only. I didn't knew you could give any fields to it to use for the real name. This is something I would like to implement, now I only hope to find time for it.

Thanks for pointing me at this.

MegaChriz’s picture

Version: 6.x-1.x-dev » 6.x-1.0
Status: Active » Needs review
FileSize
3.23 KB

It seems that the API of the RealName sounded more promising than it was. Currently the only way to integrate other modules with RealName is to 'hack' the module. More specified: you have to make a (little) change in realname_supported.inc and add a file called realname_module.inc where module is the name of the module you want to integrate.
Because of this, code for RealName integration can't be added to Ubercart Addresses.

However, I have worked out the solution. Attached are two files (packed in a zip), to be placed inside the folder of RealName. realname_supported.inc is an altered file to let RealName know Ubercart Addresses is supported and realname_uc_addresses.inc is a new file where the integration code lives.
As I'm also co-maintainer of Extra Fields Pane, I added integration for that module also (because in the Netherlands the name can exists into more parts than just first_name and last_name, for example we have a part called tussenvoegsel).

Let me know if this solution works for you.

techypaul’s picture

Hi!

Thats absolutely great news! I have installed and will test this out today. Quick once over and it seems to be working really well, cant tell you how much time this will save me :).

I see what you mean about the process/module, its not great for upgrading later. I guess this is something that realname should be including in their module rather than in yours or get them to provide a hook for other modules to get into.

Thanks,
Paul.

jvieille’s picture

Thanks, I have submitted the case to the Realname module, where it should be addressed
http://drupal.org/node/1913962

However, I am not sure this will still work. It seems that this code is no longer in sync with the module.
I was wondering about which address was used to fill up realname fields, and found this:

function uc_addresses_load_profile($account) {
  $aid = _uc_addresses_get_default_address_id($account->uid);
  if (!$aid) {
    // User has no default address, can happen
    return;
  }
  $address = _uc_addresses_db_get_address($account->uid, $aid);

Actually, there is not such _uc_addresses_get_default_address_id($account->uid) function in uc address.

I found this one which seems to match the need for selecting the proper address

 /**
   * Returns a default address
   *
   * @param string $type
   *   The address type to get (shipping, billing)
   * @access public
   * @return
   *   UcAddressesAddress if the address is found
   *   NULL otherwise
   */
  public function getDefaultAddress($type = 'billing') {
    if (isset($this->defaultAddresses[$type])) {
      return $this->defaultAddresses[$type];
    }
    if (!$this->defaultsLoaded) {
      $this->loadDefaults();
    }
    if (isset($this->defaultAddresses[$type])) {
      return $this->defaultAddresses[$type];
    }
    return NULL;
  }

However,
- it returns the address object, not the ID
- the user id is provided at the embedding class level
Also, one has to decide which default address is to be used - Billing or Shipping (I would think that Shipping is more appropriate). A setting might be provided for that.

Thanks for help on how to update this important feature.

jvieille’s picture

Status: Needs review » Needs work
MegaChriz’s picture

The Real Name integration I posted in #2 is for the 6.x-1.0 version, not for the 6.x-2.x version. I don't think it's a good idea to ask the RealName module maintainers to add support for uc_addresses, because there are two major Drupal 6 versions of uc_addresses. To support uc_addresses they should:
1. Implement code that finds out which version of uc_addresses is used.
2. Update the code in case the API of uc_addresses changes.

It would be better to ask them to add a hook that uc_addresses can implement.

MegaChriz’s picture

If you would like to port this solution to the 6.x-2.x version, you could read documentation about the address book API.

jvieille’s picture

I am not reaaly a coder, though I tried to code this one.
Any opinion before I'll test this?
This is the only function that seems to be updated

function uc_addresses_load_profile($account) {
+//change for UC Addresses 2 - get the default "shipping" address for Realname
+  $uid = $account->uid;
+  $address = UcAddressesAddressBook::get($uid)->getDefaultAddress("shipping");
+  $aid = $address->aid;
-  getDefaultAddress($type)
-  $aid = _uc_addresses_get_default_address_id($account->uid);
  if (!$aid) {
    // User has no default address, can happen
    return;
  }
-  $address = _uc_addresses_db_get_address($account->uid, $aid);
+// end change UC Address 2  
  $fields_list = realname_uc_addresses_get_fields(array());
  foreach ($fields_list['fields'] as $full_field_name => $field) {
    $field_name = $field['field_name'];
    if (isset($address->$field_name)) {
      $account->$full_field_name = $address->$field_name;
    }
  }

  // Extra Fields Pane integration
  if (module_exists('uc_extra_fields_pane')) {
    $values = uc_extra_fields_pane_value_list_load($aid, UCXF_VALUE_ADDRESS);
    foreach ($values as $value) {
      if ($value instanceof UCXF_Value) {
        // UCXF 6.x-2.x future release (September/October 2011)
        $field_name = $value->db_name;
        $account->{UC_ADDRESSES_FIELD_NAME_PREFIX . $field_name} = $value->output();
      }
      else {
        // UCXF 6.x-2.x-dev May 2011
        $field_name = $value['db_name'];
        $account->{UC_ADDRESSES_FIELD_NAME_PREFIX . $field_name} = $value['value'];
      }
    }
  }
}

Thanks!

MegaChriz’s picture

It's been a while since I last looked at integrating modules with RealName. A few quick notes:

  • You don't need to retrieve the address ID. For the 6.x-1.x version this was needed because an ID was needed to find the right address.
  • The method getDefaultAddress() from UcAddressesAddressBook can return NULL, so you have to be beware of that in your code.
  • I think the Extra Fields Pane integration code is no longer needed, because Extra Fields Pane declares its fields to Ubercart Addresses 6.x-2.x.
  • Accessing fields in Ubercart Addresses 6.x-2.x goes a bit differently compared to the 6.x-1.x version. See the documentation.
MegaChriz’s picture

I found an issue for RealName module where it is suggested a hook should be provided: #517844: Add hooks to have modules define support in themselves. I'm not sure if the maintainers still care about the 6.x version. If that's the case, then I'm afraid I will have to close this issue as "won't fix", since there wouldn't be place where this code could live except inside this issue.

MegaChriz’s picture

Assigned: MegaChriz » Unassigned
Status: Needs work » Postponed

This issue is marked as postponed until #517844: Add hooks to have modules define support in themselves is fixed. If it seems that #517844: Add hooks to have modules define support in themselves will never be fixed, then this issue will be closed as "won't fix".

jvieille’s picture

I think the issue is solved, just not committed.
I am trying to wake this up
http://drupal.org/node/517844#comment-7068814