I have a customer profile with two addressfields (commerce_customer_address and field_shipping_address). (I also have a textfield for phonenumber but I think it's irrelevant.)

I'm using commerce_addressbook to load existing customer profiles.

However, in DC core's commerce_order_commerce_customer_profile_presave() only commerce_customer_address is handled as an addressfield, field_shipping_address is not. Therefore, if I select an existing customer profile, it is handled as a new one and saved again. See line:

      if ($field_name == 'commerce_customer_address') {

This only happens if there is an existing order for that customer profile already, I'm not sure why.

Comments

rszrama’s picture

Category: bug » support
Priority: Major » Normal

I'm not sure there's a bug here; it sounds like you just may not understand why or how duplication happens. From what I can tell in your post, it sounds like duplication should be happening. Is there a reason you think it shouldn't? It's supposed to happen any time a profile is edited and saved after being referenced by an order.

czigor’s picture

Category: support » bug

I think it should not save because my profile is loaded but it's not edited.

commerce_addressbook provides a dropdown to the billing information form to select existing profiles. I choose one and without editing the fields I click 'Continue to next step'. That's when a new profile with the exact same fields gets created.

The problem is that addressfield has uninitialized variables when loaded from the database while the data obtained from form_state does not have these variables at all. This is known, that's why there's a separate if-branch for commerce_customer_address. However, if you have another addressfield it is always identified as 'changed'.

commerce_order_commerce_customer_profile_presave() has some useful comments that explain the same thing I'm trying to explain here.

rszrama’s picture

Ok, sorry, it's been a while since I wrote that code. : P

What's interesting to me is that Commerce Addressbook is loading and saving profiles at all. Maybe the issue is that it's happening before the order gets updated with the profile reference.

amateescu’s picture

Project: Commerce Core » Commerce Addressbook
Component: Customer » Code
Status: Active » Postponed (maintainer needs more info)

There's been a lot of work on a 7.x-2.x branch for Commerce Adressbook in this sandbox: http://drupal.org/sandbox/eclipsegc/1409158. Can you please give it a try and see if it fixes your problem?

itamair’s picture

mmmhhh ... I checked the 7.x-2.x branch for Commerce Adressbook in that sandbox (http://drupal.org/sandbox/eclipsegc/1409158).,
updating from this module, but still same addresses (with custom billing profile fields) get duplicated every time, though exactly identical ....

bojanz’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
bojanz’s picture

Issue summary: View changes

Provide further explanation