If an admin user is creating a new order for a customer believed to be new and it turns out the customer's email already exists, a nasty "Integrity constraint violation" is displayed. It would be nice to get a friendlier "customer already exists" error message or even automatic assignment of that existing customer to the new order.
If no change is made, all admin users will need to be trained to always assume customers are existing and start by searching for the existing customer. If the customer doesn't exist, an error message saying, "There are no entities matching email_address" appears. Then the admin user would proceed by creating the new customer.
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff-18-19.patch | 700 bytes | Nigel Cunningham |
#19 | Issue-2868368-by-ericchew-czigor-marchuk.vitaliy-s.m.patch | 6.23 KB | Nigel Cunningham |
| |||
#18 | interdiff-16-18.txt | 635 bytes | Rishi Kulshreshtha |
#18 | new-customer-with-same-email-2868368-18.patch | 5.52 KB | Rishi Kulshreshtha |
| |||
#5 | interdiff-4-5.txt | 2.89 KB | s.messaris |
Issue fork commerce-2868368
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
czigor CreditAttribution: czigor at Centarro commentedComment #4
ericchew CreditAttribution: ericchew as a volunteer commentedWhile name/mail fields are both set to mail value in the Commerce form, that is not guaranteed to be true if the User was created a different way (such as the standard User forms). I tested the patch on my site and I was able to create a duplicate user. Here is a patch that includes a check for users that have the same email address. I also updated the error text to match the message given by core when validating for unique email on User.
Adding related issue from Core regarding base field constraints.
Comment #5
s.messaris CreditAttribution: s.messaris commentedThis problem still exists today, closing https://www.drupal.org/project/commerce/issues/3166998 as a duplicate of this, but I was using the patch there in production for 2 months without any problems.
The patch in #4 here triggers some deprecation warnings in D9 and just checks the mail, I added some changes from the patch I wrote in 3166998 to fix the warnings and do a more generic validation with $user->validate(), and kept the test that should still apply and the usage of #element_validate that is better than what I did there.
If someone can review this I would much appreciate it.
Comment #6
s.messaris CreditAttribution: s.messaris commentedComment #7
s.messaris CreditAttribution: s.messaris commentedCan someone please review this?
Comment #8
Marios Anagnostopoulos CreditAttribution: Marios Anagnostopoulos as a volunteer commented#5 works for me.
This problem seems to exist like... for ever, to the point actually that we have all gotten used to it.
I believe this is good to go and will be changing the status to rtbc.
Comment #9
Marios Anagnostopoulos CreditAttribution: Marios Anagnostopoulos as a volunteer commentedComment #10
s.messaris CreditAttribution: s.messaris commentedHello, what is needed to have this committed?
Comment #11
jsacksick CreditAttribution: jsacksick at Centarro commentedInstead of using an #element_validate on the fieldset, let's just implement the
validateForm
method in OrderAddForm and OrderReassignForm.And just call:
Also, the other methods aren't static, so let's mimic that.
Regarding the functional javascript test, let's reuse OrderAdminTest (Either by updating
testCreateOrder
), or just add an additional method there (e.gtestCreateOrderNewCustomer())
, it's probably easier/faster to introduce a new method.Let's also skip
createUserObject
. After validating the user, you can put it in form state, and retrieve it from submitForm.So:
And from submitCustomerForm do
$form_state->get('customer');
.Comment #14
Rishi KulshreshthaComment #15
jsacksick CreditAttribution: jsacksick at Centarro commented@ Rishi Kulshreshtha: Any reason to assign this to you? @marchuk.vitaliy opened a PR that has passing tests?
Comment #16
Rishi Kulshreshtha@jsacksick, actually, I found the status in needs work & hence thought of checking the same. I've tried to implement the suggestions provided by you above.
I didn't actually notice the MR in the first place as the ticket already contained some patches, my bad. But, after your message I reviewed the MR provided by @marchuk.vitaliy seems to tackle all your suggestions as well, but I can see there the use of
waitForAjaxToFinish()
which is already deprecated & I've tried to create the user using DI instead of directly usingUser::create
Attaching the updated patch.
Comment #18
Rishi KulshreshthaWow,
\Drupal\Tests\user\Traits\UserCreationTrait::createUser
's signature is slightly different than\Drupal\KernelTests\Core\Entity\EntityKernelTestBase::createUser
:)Comment #19
Nigel CunninghamThe original behaviour of the form allows the creation of a user by entering an email address only. With the version of the patch in comment 18, all validations on a newly created user are applied, potentially preventing the creation of the user because of constraints related to fields that aren't on this form.
I'm attaching a version of the patch that only applies the email address constraint, to keep the behaviour the same as it was originally.
Comment #22
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted! Thanks everyone!!