diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml index 21746fcad1..adb9b2b9b7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml @@ -114,7 +114,7 @@ sylius_grid: form_options: extra_options: class: '%sylius.model.customer.class%' - choice_label: fullname + choice_label: nameOrEmail date: type: date label: sylius.ui.date diff --git a/src/Sylius/Component/Customer/Model/Customer.php b/src/Sylius/Component/Customer/Model/Customer.php index e7650fdf00..4a5921b43e 100644 --- a/src/Sylius/Component/Customer/Model/Customer.php +++ b/src/Sylius/Component/Customer/Model/Customer.php @@ -89,6 +89,21 @@ class Customer implements CustomerInterface, \Stringable return trim(sprintf('%s %s', $this->firstName, $this->lastName)); } + public function getNameOrEmail(): string + { + $fullName = $this->getFullName(); + + if ('' !== $fullName && null !== $this->email) { + return sprintf('%s (%s)', $fullName, $this->email); + } + + if ('' !== $fullName) { + return $fullName; + } + + return (string) $this->email; + } + public function getFirstName(): ?string { return $this->firstName; diff --git a/src/Sylius/Component/Customer/Model/CustomerInterface.php b/src/Sylius/Component/Customer/Model/CustomerInterface.php index cc252d4ab8..31e3720210 100644 --- a/src/Sylius/Component/Customer/Model/CustomerInterface.php +++ b/src/Sylius/Component/Customer/Model/CustomerInterface.php @@ -37,6 +37,8 @@ interface CustomerInterface extends TimestampableInterface, ResourceInterface public function getFullName(): string; + public function getNameOrEmail(): string; + public function getFirstName(): ?string; public function setFirstName(?string $firstName): void;