I noticed several older issues with similar titles, but this one is separate and does need to be solved by Address Field, AFAICS.

Since the release of 7.x-beta5, this code:

$profile_id = ID_LAST_SAVED_PRE_BETA5;
$profile = commerce_customer_profile_load($profile_id);
$profile->status = 0;
commerce_customer_profile_save($profile);

Will not actually change the status of $profile, but will create a copy with status=0.

One effect is that commerce_addressbook_customer_profile_form_submit(), if (!empty($profile->previous_id)) {, does not disable the existing profile but creates two new profiles, of which one enabled and one disabled.

Reason

commerce_order_commerce_customer_profile_presave() thinks the address field in the loaded profile is different from the one it's going to save, because

Possible fix

...in the patch: populate name_line on load. Note I'm not too exerienced with the Field (Attach) API and it's hard for me to see what the exact intended meaning of all those hooks are, and if this is the best solution. I figured hook_field_load() is meant for completion of fields because text_field_load() does basically the same.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torgosPizza’s picture

Having this same issue when migrating from Ubercart to Commerce (Kickstart). Each order ends up saving a brand new billing profile and that ends up making things look horribly broken. Will test this patch with Migrations to see if that works.

jsacksick’s picture

There are several ways of fixing this I guess, we could also write an update hook that will just update the "name_line" column directly in the DB, or actually update the comparison performed in Commerce to ignore the "name_line" (this option is probably dirtier though).

However, I think the patch looks good but I'm wondering if it's still a necessity to commit it after all these years.
The reason for that is that the patch is targeting address fields that were saved prior to the the Addressfield beta5 release which is now 5 years old...

On the other hand, if you're updating the Addressfield module now and have thousands of customer profiles, each time a profile is saved, it could potentially be duplicated because of the "name_line" comparison.

So in short, I think the patch can be committed as is, but will probably now have a limited impact (It's not useful on new sites, or installs post beta5).

jsacksick’s picture

Status: Needs review » Reviewed & tested by the community

I was able to confirm the patch is working by emptying manually the name_line column in the field_data table.
As explained by roderik, prior to the patch, simply loading and saving the profile (with no name_line) triggers a profile duplication, the problem is indeed gone with the patch.

Let's get this in.

  • bojanz committed 13ba24a on 7.x-1.x authored by roderik
    Issue #2169863 by roderik: Fix duplicate saving of customer profiles
    

bojanz credited roderik.

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Thank you both!

roderik’s picture

Thank you - this reinforced my faith in filing documented reports with patches :)

Status: Fixed » Closed (fixed)

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