Patches assume the answer to the original question below is 'yes'.

--

This is what I did:
1) Logged in as a normal user and created 3 address.
2) Set one of them as default address.
3) Add a product to cart and check.

This is what I observed on checkout page:
* System chooses either the address firstly created or one used for last checkout process to populate the billing information form. The default address is not chosen.

My questions is: Shall system uses "default address" to populate the billing information form, or not?

Thank you for your kind help in advance!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kurtfoster’s picture

I am experiencing the same issue. When a user sets an address as the default, surely that should be the address selected when they create a new order and try to checkout. This appears to be a bug.

kurtfoster’s picture

OK, so if you are looking for the functionality described in my comment above you can use this patch, it works for me. Please note, that if you create an order, then change your default address, this will not change the address on your existing order, even if you don't visit the checkout. However it will set the default address on all new orders after you change your default address.

roderik’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
3.89 KB

I agree it seems like a bug that the 'default profile' does not populate the billing/shipping address in the checkout form.

The patch in #2 correctly sets the #default_value in the addressbook dropdown, but it does not populate the elements of the addressfield. so I still can't continue to the next checkout page. In order to have the address elements filled automatically by the commerce_customer module, I set the default profile in the order before the form is built. (But don't save the order yet.)

The 2nd hunk of the patch is not strictly necesssary / doesn't make much of a difference, but (not loading the whole profile) is a small optimization.

roderik’s picture

Refinement of #3; the profile can be set in the order data too...

roderik’s picture

Title: What is the designed behavior of default address » Use default address in checkout pane
Issue summary: View changes
FileSize
8.08 KB

The patch evolved. Besides polishing up code in some places, there's one extra minor feature which I don't want to submit a separate patch for:

If an order already has an attached profile, but that profile is somehow disabled, then it should still be shown in the select list.

That did require some reshuffling in the form_alter, so the patch is a lot larger. And oh yeah, I deleted $form[$pane_id]['addressbook_entries'] because it's not used anywhere.

fietserwin’s picture

Title: Use default address in checkout pane » Default address not always used in checkout pane
Version: 7.x-2.0-rc7 » 7.x-2.x-dev
Category: Support request » Bug report

I had the same idea: I set a customer profile as default and it does not get filled in on checkout; what is the idea of this feature?

On digging in deeper I came upon this issue and the patches and thought, this cannot be true. So I dived in even deeper into the code and found this:
- commerce_addressbook implements hook_commerce_order_insert()
- this hook sets the value of the order field whose name is stored in the variable commerce_{profile_type}_field to the default profile id for that type (if not already set).

So far so good, but:
- It seems that only the billing profile has a field on order (customer_billing_profile), other profile types are stored in the more flexible order data. Compare code in file commerce_customer.checkout_pane.inc, where you often see code like:

  if ($field_name = variable_get('commerce_' . $checkout_pane['pane_id'] . '_field', '')) {
    ... do something with $order->{$field_name} ...
  }
  else {
    // Or try the association stored in the order's data array if no field is set.
    ... do something with $order->data['profiles'][$checkout_pane['pane_id']] ...
  }

- This hook is called when a cart gets created, which is when a product gets added to a visitor not yet having a cart. However, emptying the cart does not seem to remove the empty order. This hindered me during testing as sometimes I did get the desired behavior, sometimes not. I really had to delete the cart using the store admin UI (admin/commerce/orders/carts).
- This hook gets called after inserting the new order, leading directly to an update on the just created order. I think this feature should better be placed in the commerce_order_presave hook as the order id is not needed.

This patch:
- Changes the hook_commerce_order_insert() into a hook_commerce_order_presave() to prevent a 2nd database access directly after inserting.
- Also works for profiles that are stored in the order's data array. (this is the real bug in this issue!)
- I did not test the latter, as in my case I only have a billing address.
- I did test it with billing addresses and that works fine for me.

fietserwin’s picture

FileSize
2.4 KB

And the patch ...

ath.galanis’s picture

Patch in #7 seems to work fine for me, with both Billing and Shipping profiles in my orders.

Thank you.

adevms’s picture

Patch #7 worked for me as well.
Thanks

fietserwin’s picture

Status: Needs review » Reviewed & tested by the community

Based on #8 and #9.

deepbluesolutions’s picture

have tested this and agree the #7 worked for us.

yuseferi’s picture

# work correctly for me. thank you ;)

jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

  • jsacksick committed d8fad28 on 7.x-2.x authored by fietserwin
    Issue #2070643 by roderik, fietserwin: Fix default address not always...

Status: Fixed » Closed (fixed)

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

nachus’s picture

Hi, i'm getting the same error, default address not always used in checkout pane.
Tried with 7.x-2.0-rc9 and 7.x-2.x-dev. Drupal 7.50.

I created 2 customer profiles and when i went to the checkout the first profile is allways selected.
I also tried with fresh drupal installation and got the same results.

Thanks in advance!!

lukasss’s picture

I hav same @nachus now

vasyl.kletsko’s picture

I have the same bug

wellme’s picture

I have the same bug.

jsacksick’s picture

Did you try switching to the 3.x version?

wellme’s picture

@jsacksick Thank you for the suggestion. Works fine now.