Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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!
Comment | File | Size | Author |
---|---|---|---|
#7 | 2070643-6.patch | 2.4 KB | fietserwin |
#5 | addressbook-ensure-default-address-selected-in-checkout-2070643-5.patch | 8.08 KB | roderik |
#2 | addressbook-ensure-default-address-selected-in-checkout-2070643-1.patch | 1004 bytes | kurtfoster |
Comments
Comment #1
kurtfoster CreditAttribution: kurtfoster commentedI 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.
Comment #2
kurtfoster CreditAttribution: kurtfoster commentedOK, 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.
Comment #3
roderikI 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.
Comment #4
roderikRefinement of #3; the profile can be set in the order data too...
Comment #5
roderikThe 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.Comment #6
fietserwinI 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:
- 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.
Comment #7
fietserwinAnd the patch ...
Comment #8
ath.galanis CreditAttribution: ath.galanis commentedPatch in #7 seems to work fine for me, with both Billing and Shipping profiles in my orders.
Thank you.
Comment #9
adevms CreditAttribution: adevms commentedPatch #7 worked for me as well.
Thanks
Comment #10
fietserwinBased on #8 and #9.
Comment #11
deepbluesolutions CreditAttribution: deepbluesolutions commentedhave tested this and agree the #7 worked for us.
Comment #12
yuseferi CreditAttribution: yuseferi commented# work correctly for me. thank you ;)
Comment #13
jsacksick CreditAttribution: jsacksick commentedCommitted, thanks!
Comment #16
nachus CreditAttribution: nachus commentedHi, 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!!
Comment #17
lukasss CreditAttribution: lukasss commentedI hav same @nachus now
Comment #18
vasyl.kletsko CreditAttribution: vasyl.kletsko commentedI have the same bug
Comment #19
wellme CreditAttribution: wellme at Zyxware Technologies commentedI have the same bug.
Comment #20
jsacksick CreditAttribution: jsacksick at Centarro commentedDid you try switching to the 3.x version?
Comment #21
wellme CreditAttribution: wellme at Zyxware Technologies commented@jsacksick Thank you for the suggestion. Works fine now.