Problem/Motivation

The address book API has a flaw regarding setting default addresses. Currently, when you set an address as the default billing or default shipping through the API, you should take care for saving all addresses or else multiple addresses get marked as the same default type.
Though this behaviour is documented, the API should not allow this.
I've found out that this can lead to serious problems when working on addresses with third party modules, such as with Views Bulk Operations (this module has an option to change a value of an entity and "default billing" is one of the values that can be changed on address entities).

Proposed resolution

When saving an address, the API should check if the address is a default address. If that's the case, it should execute an additional query to ensure no other addresses of the user's address book are marked as the same default type.

Remaining tasks

  • Implement the proposed solution.
  • Extend the API test to ensure the problem is solved.

User interface changes

None.

API changes

For module developers it will be no longer required to save all addresses when they set an address as the default address.

I'm working on it.

Comments

megachriz’s picture

As it's hard to extend the API test at the moment, I've opened a new issue for refactoring that test: #1986800: Refactor UcAddressesApiTestCase. That issue should first be fixed before a patch with a test can be provided for this issue.

megachriz’s picture

Here are two patches. The first patch includes the fix and a test. The second patch contains the test only to ensure the test is failing without the fix.

Status: Needs review » Needs work
megachriz’s picture

Status: Needs work » Needs review

The second patch in #2 was supposed to be failing tests. Back to "needs review".

megachriz’s picture

In addition of the patch in #2, this patch makes setting a default addresses using the API and saving an addresses using the UI slightly more efficient.

Previously, all addresses were loaded when setting an other address is default to be absolutely sure no other address is marked as the same default type. Now only the default address(es) are loaded.
And when saving a single address in the UI, always all addresses (of the address owner) were loaded and saved to prevent having two addresses marked as the same default type.

If this patch doesn't break tests, I think it's ready for commit.

megachriz’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed #5.

Moving to 6.x-2.x.

megachriz’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new5.21 KB

Patch for the 6.x-2.x version.

megachriz’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Fixed

Committed #7.

Setting issue back to the version it was originally reported for and mark it as fixed.

Status: Fixed » Closed (fixed)

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