diff --git a/features/user/managing_customers/adding_customer_account.feature b/features/user/managing_customers/adding_customer_account.feature index bd4dcda33571..931b53337575 100644 --- a/features/user/managing_customers/adding_customer_account.feature +++ b/features/user/managing_customers/adding_customer_account.feature @@ -26,5 +26,6 @@ Feature: Adding a new customer account And I specify their password as "killSauron" And I save my changes Then I should be notified that it has been successfully edited + And I should not see create account option And the customer "f.baggins@example.com" should appear in the store And this customer should have an account created diff --git a/src/Sylius/Bundle/CoreBundle/EventListener/DefaultUsernameORMListener.php b/src/Sylius/Bundle/CoreBundle/EventListener/DefaultUsernameORMListener.php index f49d8f52ac3b..75bfcaae2df3 100644 --- a/src/Sylius/Bundle/CoreBundle/EventListener/DefaultUsernameORMListener.php +++ b/src/Sylius/Bundle/CoreBundle/EventListener/DefaultUsernameORMListener.php @@ -18,6 +18,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\UnitOfWork; use Sylius\Component\Core\Model\CustomerInterface; +use Sylius\Component\Core\Model\ShopUserInterface; /** * Keeps user's username synchronized with email. @@ -35,13 +36,20 @@ public function onFlush(OnFlushEventArgs $onFlushEventArgs) private function processEntities(array $entities, EntityManagerInterface $entityManager, UnitOfWork $unitOfWork): void { - foreach ($entities as $customer) { - if (!$customer instanceof CustomerInterface) { + foreach ($entities as $entity) { + if (!$entity instanceof ShopUserInterface && !$entity instanceof CustomerInterface) { continue; } - $user = $customer->getUser(); - if (null === $user) { + if ($entity instanceof ShopUserInterface) { + $user = $entity; + $customer = $user->getCustomer(); + } else { + $customer = $entity; + $user = $customer->getUser(); + } + + if (!$customer || !$user) { continue; }