From 5a125180a41d8bd901551eb32b07231b010ec2d5 Mon Sep 17 00:00:00 2001 From: Rostislav Vitek Date: Thu, 10 Oct 2024 17:00:01 +0200 Subject: [PATCH] FE API: order creation: email is always taken from the logged user --- src/Model/Mutation/Order/CreateOrderMutation.php | 13 ++++++++++--- .../Order/Input/OrderInputDecorator.types.yaml | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Model/Mutation/Order/CreateOrderMutation.php b/src/Model/Mutation/Order/CreateOrderMutation.php index e74d61bae..3e9813f5b 100644 --- a/src/Model/Mutation/Order/CreateOrderMutation.php +++ b/src/Model/Mutation/Order/CreateOrderMutation.php @@ -8,6 +8,7 @@ use Overblog\GraphQLBundle\Validator\InputValidator; use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser; +use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser; use Shopsys\FrameworkBundle\Model\Order\PlaceOrderFacade; use Shopsys\FrameworkBundle\Model\Order\Processing\OrderInputFactory; use Shopsys\FrameworkBundle\Model\Order\Processing\OrderProcessor; @@ -23,6 +24,7 @@ class CreateOrderMutation extends AbstractMutation { public const string VALIDATION_GROUP_IS_DELIVERY_ADDRESS_DIFFERENT_FROM_BILLING_WITHOUT_PRESELECTED = 'isDeliveryAddressDifferentFromBillingWithoutPreselected'; public const string VALIDATION_GROUP_ON_COMPANY_BEHALF = 'onCompanyBehalf'; + public const string VALIDATION_GROUP_ANONYMOUS_USER = 'anonymousUser'; /** * @param \Shopsys\FrontendApiBundle\Model\Order\OrderDataFactory $orderDataFactory @@ -55,14 +57,14 @@ public function __construct( */ public function createOrderMutation(Argument $argument, InputValidator $validator): CreateOrderResult { - $validationGroups = $this->computeValidationGroups($argument); + $customerUser = $this->currentCustomerUser->findCurrentCustomerUser(); + $validationGroups = $this->computeValidationGroups($argument, $customerUser); $validator->validate($validationGroups); $orderData = $this->orderDataFactory->createOrderDataFromArgument($argument); $input = $argument['input']; $cartUuid = $input['cartUuid']; - $customerUser = $this->currentCustomerUser->findCurrentCustomerUser(); $cart = $this->cartApiFacade->getCartCreateIfNotExists($customerUser, $cartUuid); $cartWithModifications = $this->cartWatcherFacade->getCheckedCartWithModifications($cart); @@ -93,9 +95,10 @@ public function createOrderMutation(Argument $argument, InputValidator $validato /** * @param \Overblog\GraphQLBundle\Definition\Argument $argument + * @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser|null $currentCustomerUser * @return string[] */ - protected function computeValidationGroups(Argument $argument): array + protected function computeValidationGroups(Argument $argument, ?CustomerUser $currentCustomerUser): array { $input = $argument['input']; $validationGroups = ['Default']; @@ -108,6 +111,10 @@ protected function computeValidationGroups(Argument $argument): array $validationGroups[] = self::VALIDATION_GROUP_IS_DELIVERY_ADDRESS_DIFFERENT_FROM_BILLING_WITHOUT_PRESELECTED; } + if ($currentCustomerUser === null) { + $validationGroups[] = self::VALIDATION_GROUP_ANONYMOUS_USER; + } + return $validationGroups; } } diff --git a/src/Resources/config/graphql-types/ModelType/Order/Input/OrderInputDecorator.types.yaml b/src/Resources/config/graphql-types/ModelType/Order/Input/OrderInputDecorator.types.yaml index e16557b67..20380aac6 100644 --- a/src/Resources/config/graphql-types/ModelType/Order/Input/OrderInputDecorator.types.yaml +++ b/src/Resources/config/graphql-types/ModelType/Order/Input/OrderInputDecorator.types.yaml @@ -33,16 +33,19 @@ OrderInputDecorator: max: 100 maxMessage: "Last name cannot be longer than {{ limit }} characters" email: - type: "String!" + type: "String" description: "The customer's email address" validation: - NotBlank: message: "Please enter email" + groups: "anonymousUser" - Email: message: "Please enter valid email" + groups: "anonymousUser" - Length: max: 255 maxMessage: "Email cannot be longer than {{ limit }} characters" + groups: "anonymousUser" telephone: type: "String!" description: "The customer's phone number"