diff --git a/src/Spryker/Zed/Customer/Communication/Form/CustomerForm.php b/src/Spryker/Zed/Customer/Communication/Form/CustomerForm.php index 3ba31515..c028a30d 100644 --- a/src/Spryker/Zed/Customer/Communication/Form/CustomerForm.php +++ b/src/Spryker/Zed/Customer/Communication/Form/CustomerForm.php @@ -390,9 +390,11 @@ protected function addDateOfBirthField(FormBuilderInterface $builder) } /** + * @param string|null $currentEmail + * * @return list<\Symfony\Component\Validator\Constraint> */ - protected function createEmailConstraints(): array + protected function createEmailConstraints(?string $currentEmail = null): array { $emailConstraints = [ new NotBlank(), @@ -403,7 +405,11 @@ protected function createEmailConstraints(): array $customerQuery = $this->getQueryContainer()->queryCustomers(); $emailConstraints[] = new Callback([ - 'callback' => function ($email, ExecutionContextInterface $context) use ($customerQuery) { + 'callback' => function ($email, ExecutionContextInterface $context) use ($customerQuery, $currentEmail) { + if ($currentEmail !== null && $email === $currentEmail) { + return; + } + if ($customerQuery->findByEmail($email)->count() > 0) { $context->addViolation('Email is already used'); } diff --git a/src/Spryker/Zed/Customer/Communication/Form/CustomerUpdateForm.php b/src/Spryker/Zed/Customer/Communication/Form/CustomerUpdateForm.php index 6281c701..bcc0e57b 100644 --- a/src/Spryker/Zed/Customer/Communication/Form/CustomerUpdateForm.php +++ b/src/Spryker/Zed/Customer/Communication/Form/CustomerUpdateForm.php @@ -105,10 +105,10 @@ protected function addStoreField(FormBuilderInterface $builder, array $choices) */ protected function addEmailField(FormBuilderInterface $builder) { + $currentEmail = $builder->getData()[static::FIELD_EMAIL] ?? null; $builder->add(static::FIELD_EMAIL, EmailType::class, [ 'label' => 'Email', - 'constraints' => $this->createEmailConstraints(), - 'disabled' => 'disabled', + 'constraints' => $this->createEmailConstraints($currentEmail), ]); return $this;