Skip to content

Commit

Permalink
Bug #10951 [Account] fix sync username with customer email
Browse files Browse the repository at this point in the history
if applied, this commit will

-make sync behaviour works on both customer and shop user,
resulting in username will never by setting username value whenever
shopuser or customer are inserted or updated.
  • Loading branch information
hatem20 committed Jun 16, 2020
1 parent cc56808 commit 6783d5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down

0 comments on commit 6783d5c

Please sign in to comment.