Problem/Motivation

When selecting an address from a previous order at checkout, only the "default" address fields will be populated. Fields that are defined through Ubercart Addresses' field handler API currently remain empty. This is wrong, extra address fields should also be populated.

When this problem occurs

Normally, customers can select addresses from their address book at checkout. If, however, their address book is empty, but they have previous orders, the address selecting at checkout will fallback to previous orders, which is also Ubercart's default behavior.
Customers can have an empty address book if they are not required to enter one when they register or if Ubercart Addresses was installed on an existing site.
Addresses entered at checkout are automatically saved to the address book, but addresses entered on the order admin pages are not.
For this problem to occur, there need to be extra address fields that are defined through the Ubercart Addresses' field handler API and they must be filled for previous orders.

So, this problem generally only occurs when there are orders created by admins where the extra fields had values.

How to reproduce

  1. Enable a module that defines extra address fields for Ubercart Addresses. The easiest one to take is the Ubercart Addresses Example module (already included as a submodule).
  2. Go the address settings page (admin/store/settings/addresses) and turn off "Require admins to enter an address upon user creation" setting.
  3. Create an user without any addresses.
  4. Create an order for this user in the order admin section (admin/store/orders/create). Fill in the extra address fields.
  5. Log in as this user, add a product to the cart and go to checkout.

When you now select an address, the extra address fields will remain empty.

Proposed resolution

Ubercart Addresses currently uses the function uc_get_addresses to retrieve addresses from previous orders (see ± line 324 in uc_addresses.uc_addresses_fields.inc). The query executed in uc_get_addresses isn't alterable by other modules, so Ubercart Addresses should implement it's own version that includes a query that is alterable. Modules that define extra address fields and store the values for these fields in the uc_orders table will not need to alter the query (at least, when they followed the same name convention as the other address fields: (address type)_(field name)). Modules that store extra address field values in an other table will have a chance to alter the query. The module Extra Fields Pane is a good example for this case.

Remaining tasks

  • Implement own version of uc_get_addresses.
  • Make sure the query is alterable by other modules by adding query tags.
  • Write an automated test for this case.

User interface changes

When selecting an address from a previous order, the extra address fields from which values are stored in the uc_orders table should also be populated on the address form.

API changes

Modules will get a chance to alter the query that selects addresses from previous orders by implementing hook_query_alter() or hook_query_TAG_alter()

I'm working on a patch.

Comments

megachriz’s picture

Status: Active » Needs review
StatusFileSize
new2.26 KB

The attached patch introduces a new function called uc_addresses_get_addresses which is based on uc_get_addresses. Two tags are added to the query:

  • a plain tag called "uc_get_addresses".
  • a dynamic tag starting with "address_type:" and ending with the address type where addresses were requested for. Examples: address_type:delivery, address_type:billing.

This case could also use an automated test. I will try to write a test for this case later.

megachriz’s picture

The attached patch also adjusts the automated test "UcAddressesCartCheckoutTestCase". In the existing "testCheckoutWithPreviousOrders" test, populating of extra address fields is now tested.

megachriz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Added task "Write an automated test for this case."