diff --git a/spec/CommandProvider/ShopUserBasedCommandProviderSpec.php b/spec/CommandProvider/ShopUserBasedCommandProviderSpec.php deleted file mode 100644 index f32e33962..000000000 --- a/spec/CommandProvider/ShopUserBasedCommandProviderSpec.php +++ /dev/null @@ -1,47 +0,0 @@ -beConstructedWith(TestShopUserBasedRequest::class, $validator); - } - - function it_implements_shop_user_command_provider_interface(): void - { - $this->shouldHaveType(ShopUserBasedCommandProviderInterface::class); - } - - function it_validates_request( - ValidatorInterface $validator, - Request $httpRequest, - ConstraintViolationListInterface $constraintViolationList, - ShopUserInterface $user - ): void { - $httpRequest->attributes = new ParameterBag(['token' => 'sample_cart_token']); - $user->getEmail()->willReturn('example@example.com'); - - $validator - ->validate(TestShopUserBasedRequest::fromHttpRequestAndShopUser( - $httpRequest->getWrappedObject(), - $user->getWrappedObject() - )) - ->willReturn($constraintViolationList) - ; - - $this->validate($httpRequest, $user)->shouldReturn($constraintViolationList); - } -} diff --git a/src/CommandProvider/ShopUserBasedCommandProvider.php b/src/CommandProvider/ShopUserBasedCommandProvider.php deleted file mode 100644 index 540cd16bc..000000000 --- a/src/CommandProvider/ShopUserBasedCommandProvider.php +++ /dev/null @@ -1,48 +0,0 @@ -requestClass = $requestClass; - $this->validator = $validator; - } - - public function validate(Request $httpRequest, ?ShopUserInterface $user): ConstraintViolationListInterface - { - return $this->validator->validate($this->transformHttpRequest($httpRequest, $user)); - } - - public function getCommand(Request $httpRequest, ?ShopUserInterface $user): CommandInterface - { - return $this->transformHttpRequest($httpRequest, $user)->getCommand(); - } - - private function transformHttpRequest(Request $httpRequest, ?ShopUserInterface $user): ShopUserBasedRequestInterface - { - /** @var ShopUserBasedRequestInterface $request */ - $request = $this->requestClass::fromHttpRequestAndShopUser($httpRequest, $user); - - return $request; - } -} diff --git a/src/CommandProvider/ShopUserBasedCommandProviderInterface.php b/src/CommandProvider/ShopUserBasedCommandProviderInterface.php deleted file mode 100644 index 48c5eb57a..000000000 --- a/src/CommandProvider/ShopUserBasedCommandProviderInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -viewHandler = $viewHandler; @@ -45,18 +42,11 @@ public function __construct( public function __invoke(Request $request): Response { try { - $orderToken = $request->attributes->get('token'); - $email = $request->request->get('email'); - - if (null !== $email) { - $this->bus->dispatch(new AssignCustomerToCart($orderToken, $email)); + if (null !== $request->request->get('email')) { + $this->bus->dispatch($this->assignCustomerToCartCommandProvider->getCommand($request)); } - $this->bus->dispatch(new CompleteOrder($orderToken, $request->request->get('notes'))); - -// try { -// $this->bus->dispatch($this->assignCustomerToCartCommandProvider->getCommand($request, $user)); -// $this->bus->dispatch($this->completeOrderCommandProvider->getCommand($request)); + $this->bus->dispatch($this->completeOrderCommandProvider->getCommand($request)); } catch (HandlerFailedException $exception) { $previousException = $exception->getPrevious(); diff --git a/src/Request/Cart/AssignCustomerToCartRequest.php b/src/Request/Cart/AssignCustomerToCartRequest.php index fb4c28407..53571d4e3 100644 --- a/src/Request/Cart/AssignCustomerToCartRequest.php +++ b/src/Request/Cart/AssignCustomerToCartRequest.php @@ -4,13 +4,12 @@ namespace Sylius\ShopApiPlugin\Request\Cart; -use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\ShopApiPlugin\Command\Cart\AssignCustomerToCart; use Sylius\ShopApiPlugin\Command\CommandInterface; -use Sylius\ShopApiPlugin\Request\ShopUserBasedRequestInterface; +use Sylius\ShopApiPlugin\Request\RequestInterface; use Symfony\Component\HttpFoundation\Request; -class AssignCustomerToCartRequest implements ShopUserBasedRequestInterface +class AssignCustomerToCartRequest implements RequestInterface { /** @var string|null */ protected $token; @@ -18,15 +17,15 @@ class AssignCustomerToCartRequest implements ShopUserBasedRequestInterface /** @var string|null */ protected $email; - private function __construct(Request $request, ?string $email) + private function __construct(Request $request) { $this->token = $request->attributes->get('token'); - $this->email = $request->request->get('email', $email); + $this->email = $request->request->get('email'); } - public static function fromHttpRequestAndShopUser(Request $request, ?ShopUserInterface $user): ShopUserBasedRequestInterface + public static function fromHttpRequest(Request $request): RequestInterface { - return new self($request, $user !== null ? $user->getEmail() : null); + return new self($request); } public function getCommand(): CommandInterface diff --git a/src/Request/ShopUserBasedRequestInterface.php b/src/Request/ShopUserBasedRequestInterface.php deleted file mode 100644 index 69d60aafc..000000000 --- a/src/Request/ShopUserBasedRequestInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - %sylius.shop_api.request.assign_customer_to_cart.class% diff --git a/tests/Test/TestShopUserBasedCommand.php b/tests/Test/TestShopUserBasedCommand.php deleted file mode 100644 index da13a9537..000000000 --- a/tests/Test/TestShopUserBasedCommand.php +++ /dev/null @@ -1,32 +0,0 @@ -token = $token; - $this->email = $email; - } - - public function token(): string - { - return $this->token; - } - - public function email(): string - { - return $this->email; - } -} diff --git a/tests/Test/TestShopUserBasedRequest.php b/tests/Test/TestShopUserBasedRequest.php deleted file mode 100644 index 60a15b787..000000000 --- a/tests/Test/TestShopUserBasedRequest.php +++ /dev/null @@ -1,35 +0,0 @@ -token = $request->attributes->get('token'); - $this->email = $email; - } - - public static function fromHttpRequestAndShopUser(Request $request, ?ShopUserInterface $user): ShopUserBasedRequestInterface - { - return new self($request, $user->getEmail()); - } - - public function getCommand(): CommandInterface - { - return new TestShopUserBasedCommand($this->token, $this->email); - } -}