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.
Say i am in checkout and i go to profile and change my mail id. it doesn't reflect in order mail property.
the user entity in order is updated though. so i use getCustomer() and call getEmail() on the user entity and then set order->setEmail() for this.
But yet to find the correct place to change this behaviour in commerce core. Mostly it might be in orderRefresh ???
Comment | File | Size | Author |
---|---|---|---|
#39 | 2873526-38.patch | 3.04 KB | jsacksick |
|
Comments
Comment #2
mglamanCross posting my thought from #2873685: Order E-Mail is not set when logging in or registering on Login pane.
A feature would be for
commerce_order
to check if a user has changed their email address. In the event this happens, we load all draft orders which belong to the user and update/sync their email field.Comment #3
sumanthkumarc CreditAttribution: sumanthkumarc at Azri Solutions commented@matt i actually liked this comment of yours:
Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedChecked 1.x, and it kept only the cart orders up to date:
So some kind of order refresh, Order::preSave() logic would be consistent with that.
Comment #5
steveoliver CreditAttribution: steveoliver at Circatree commentedThen aside from carts, @bojanz would the recommendation for this situation be to "reassign" the order to the updated customer (user)? (If you don't know about it already, see the "Reassign" operation, available on the Orders page.)
Comment #6
steveoliver CreditAttribution: steveoliver at Circatree commentedDisregard my last comment, I see the OP is only concerned with carts, not placed orders.
Comment #7
joachim CreditAttribution: joachim as a volunteer commentedThis is a corner case, granted, but it's surely a bug:
1. user creates a cart
2. user changes their email in their account
3. user completes checkout, and doesn't receive a receipt.
Comment #8
joachim CreditAttribution: joachim commentedFurthermore, this is going to have an effect on recurring orders from Commerce Recurring, where it's definitely NOT a corner case, since an order stays in draft for the whole billing period, which could be something like a year.
Comment #9
vasikeHere is patch for this
Following Bojan's suggestions: Update emails for all not placed orders of the user.
Also removed !$this->getEmail() for updating order
And update the Kernel Entity Order test for these changes.
p.s. Not sure about Commerce Recurring cases.
Comment #11
joachim CreditAttribution: joachim commented> p.s. Not sure about Commerce Recurring cases.
Commerce Recurring keeps recurring order in the 'draft' state and with placed = NULL until they are charged to the customer, so the approach in #9 looks ok to me for that case.
Comment #12
vasikeIt seems the tests fails because of "!$this->getEmail()" removal update.
So we need other approach:
For example extra check for customer mail
seems to work for CheckoutOrderTest::testGuestOrderCheckout
Could it be this what's needed here?
Comment #13
vasikeHere is a new patch that should fix the broken test - check directly about the customer email when updating an order.
Comment #15
vasikeHere is a new updated patch the should fix the tests.
Broken CouponRedemptionPaneTest it should be solved by another patch from other issue.
See #2884210-8: Hide the coupon redemption form behind a link
Comment #17
vasikeThe test fail is not related with an issue.
So i think we're in "Needs review" for now.
Comment #18
joachim CreditAttribution: joachim commentedMinor optimization: set the user email in a variable rather than keep getting it.
Comment #19
vasike@joachim thanks for suggestions.
Here is a new update for the patch : use variable for (customer) user mail value
Comment #21
vasikeThe test fail is not related with an issue.
So i think we're in "Needs review" for now.
Comment #22
jeroendegloire CreditAttribution: jeroendegloire at Calibrate commentedComment #24
unrealauk CreditAttribution: unrealauk at AnyforSoft for Drupal Ukraine Community commentedUpdated the patch, please review.
Comment #26
Neograph734I accidentally stumbled upon this issue, but I wanted to shine another light on this issue.
Doesn't commerce fill this data too early? Wouldn't it make sense to copy the customer mail only just before completing the checkout (I understand that potentially interfere with some events).
I also noticed that IP addresses do not update. The IP used during order creation is logged (could even be the admin's), but if I then login to another computer the initial IP address remains in place.
Isn't the data during order checkout more relevant than the data during creation?
It might also be an option to include the email in the profile, that would keep all customer data in one place and visible and easy editable during checkout?
Comment #27
xamount CreditAttribution: xamount as a volunteer commentedI tested the patch at #24 on an install using Commerce recurring. The draft order was successfully updated with the new email. But the original order's email was not.
Comment #28
drupal786 CreditAttribution: drupal786 at Billit Corp. commentedI have tested #24 and found its throwing error in the hook_ENTITY_TYPE_update for the argument passed, so i have updated the patch slightly to specify exact type of argument and now its working fine for me.
Comment #29
xamount CreditAttribution: xamount as a volunteer commentedSee child issue here to update all orders upon customer email change: #3200326: Updating email in Drupal user account doesn't update email in completed orders details
Comment #30
xamount CreditAttribution: xamount as a volunteer commentedPatch in #28 has worked for me (for all commerce recurring draft orders). Thanks!
To get ALL orders updated, in addition to #28 patch, I applied patch from #3200326: Updating email in Drupal user account doesn't update email in completed orders details and it works.
Comment #31
xamount CreditAttribution: xamount as a volunteer commentedComment #32
samuhe CreditAttribution: samuhe as a volunteer commentedI can confirm the patch in #28 is working.
Comment #33
jsacksick CreditAttribution: jsacksick at Centarro commentedUpdated the patch to query only for "draft" orders.
Also, querying orders that don't already have the right email.
Fixed the tests.
The only thing I'm wondering is whether this code belong to the cart module (Since the order assignment logic lives there)... But I guess it can stay in the order module as we don't check the "cart" flag.
Comment #34
jsacksick CreditAttribution: jsacksick at Centarro commentedhm... actually, I'm not sure about the order presave change... As this could update the order email of placed orders...
And.. This would actually prevent an actual update from the UI as the value set on the customer would always override the order email.
I think we should either remove the order presave change, or limit it to draft orders.
The attached patch is maintaining the order email only for draft orders. Once an order is no longer a draft, it shouldn't be magically updated...
Comment #37
mglamanI feel like this could go wrong in many ways. If we have orders ensuring the email is fresh, let's ditch this hook.
Checkout causes an order to be saved whenever the step changes, or whenever its even refreshed.
We could move this to a refresh to ensure it's always up to date. But I think draft orders get saved enough that it'll catch user email changes.
Test failure:
I bet this email update sync shows a test with bad data, that's why it failed.
Comment #38
jsacksick CreditAttribution: jsacksick at Centarro commentedSo what about this instead?
The only potential problem I see with this is potentially reverting an intentional change made to the email address (e.g if a checkout pane allows explicitly specifying an email address for example)...
Comment #39
jsacksick CreditAttribution: jsacksick at Centarro commentedBetter with the patch. The other problem I see with this approach is that until the order is refreshed, the order email is potentially wrong.
Comment #40
mglamanYeah. The only time I could see an issue is if the admin placed the order for the customer. Otherwise, the order refreshes pretty often when a customer is using it. Like every checkout step save.
Comment #41
jsacksick CreditAttribution: jsacksick at Centarro commentedSo, are we good with this approach?
Comment #44
jsacksick CreditAttribution: jsacksick at Centarro commentedIn the absence of feedback, committed the fix.
Comment #46
xamount CreditAttribution: xamount as a volunteer commentedI removed patch #28 and updated Drupal commerce (that now includes the fix in #39) but commerce recurring draft orders are not updated if the user changes their email. Patch #28 was working for me though but I cannot use it anymore as I updated Drupal commerce.
Comment #47
xamount CreditAttribution: xamount as a volunteer commentedPlease see the issue already created here: #3200326: Updating email in Drupal user account doesn't update email in completed orders details