diff --git a/doc/swagger.yml b/doc/swagger.yml index c41e14c62..676e5346f 100644 --- a/doc/swagger.yml +++ b/doc/swagger.yml @@ -543,6 +543,8 @@ paths: description: "Invalid input, validation failed." schema: $ref: "#/definitions/GeneralError" + 403: + description: "Not logged in or wrong email" /taxon-products-by-slug/{slug}: get: tags: diff --git a/src/Controller/Checkout/CompleteOrderAction.php b/src/Controller/Checkout/CompleteOrderAction.php index 9c8262dfa..ddd95292f 100644 --- a/src/Controller/Checkout/CompleteOrderAction.php +++ b/src/Controller/Checkout/CompleteOrderAction.php @@ -7,12 +7,11 @@ use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; use League\Tactician\CommandBus; -use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\ShopApiPlugin\Command\CompleteOrder; use Sylius\ShopApiPlugin\Exception\NotLoggedInException; +use Sylius\ShopApiPlugin\Provider\LoggedInUserProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\TokenNotFoundException; final class CompleteOrderAction @@ -23,14 +22,17 @@ final class CompleteOrderAction /** @var CommandBus */ private $bus; - /** @var TokenStorageInterface */ - private $tokenStorage; + /** @var LoggedInUserProviderInterface */ + private $loggedInUserProvider; - public function __construct(ViewHandlerInterface $viewHandler, CommandBus $bus, TokenStorageInterface $tokenStorage) - { + public function __construct( + ViewHandlerInterface $viewHandler, + CommandBus $bus, + LoggedInUserProviderInterface $loggedInUserProvider + ) { $this->viewHandler = $viewHandler; $this->bus = $bus; - $this->tokenStorage = $tokenStorage; + $this->loggedInUserProvider = $loggedInUserProvider; } public function __invoke(Request $request): Response @@ -66,12 +68,10 @@ public function __invoke(Request $request): Response private function provideUserEmail(Request $request): string { - $user = $this->tokenStorage->getToken()->getUser(); - - if ($user instanceof ShopUserInterface) { - return $user->getCustomer()->getEmail(); + try { + return $this->loggedInUserProvider->provide()->getEmail(); + } catch (TokenNotFoundException $tokenNotFoundException) { + return $request->request->get('email'); } - - return $request->request->get('email'); } } diff --git a/src/Resources/config/services/actions/checkout.xml b/src/Resources/config/services/actions/checkout.xml index b94d9bfc7..e1d31ef66 100644 --- a/src/Resources/config/services/actions/checkout.xml +++ b/src/Resources/config/services/actions/checkout.xml @@ -43,7 +43,7 @@ > - +