Skip to content

Commit 5a12518

Browse files
FE API: order creation: email is always taken from the logged user
1 parent 410a586 commit 5a12518

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Model/Mutation/Order/CreateOrderMutation.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Overblog\GraphQLBundle\Validator\InputValidator;
99
use Shopsys\FrameworkBundle\Component\Domain\Domain;
1010
use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser;
11+
use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser;
1112
use Shopsys\FrameworkBundle\Model\Order\PlaceOrderFacade;
1213
use Shopsys\FrameworkBundle\Model\Order\Processing\OrderInputFactory;
1314
use Shopsys\FrameworkBundle\Model\Order\Processing\OrderProcessor;
@@ -23,6 +24,7 @@ class CreateOrderMutation extends AbstractMutation
2324
{
2425
public const string VALIDATION_GROUP_IS_DELIVERY_ADDRESS_DIFFERENT_FROM_BILLING_WITHOUT_PRESELECTED = 'isDeliveryAddressDifferentFromBillingWithoutPreselected';
2526
public const string VALIDATION_GROUP_ON_COMPANY_BEHALF = 'onCompanyBehalf';
27+
public const string VALIDATION_GROUP_ANONYMOUS_USER = 'anonymousUser';
2628

2729
/**
2830
* @param \Shopsys\FrontendApiBundle\Model\Order\OrderDataFactory $orderDataFactory
@@ -55,14 +57,14 @@ public function __construct(
5557
*/
5658
public function createOrderMutation(Argument $argument, InputValidator $validator): CreateOrderResult
5759
{
58-
$validationGroups = $this->computeValidationGroups($argument);
60+
$customerUser = $this->currentCustomerUser->findCurrentCustomerUser();
61+
$validationGroups = $this->computeValidationGroups($argument, $customerUser);
5962
$validator->validate($validationGroups);
6063

6164
$orderData = $this->orderDataFactory->createOrderDataFromArgument($argument);
6265

6366
$input = $argument['input'];
6467
$cartUuid = $input['cartUuid'];
65-
$customerUser = $this->currentCustomerUser->findCurrentCustomerUser();
6668
$cart = $this->cartApiFacade->getCartCreateIfNotExists($customerUser, $cartUuid);
6769

6870
$cartWithModifications = $this->cartWatcherFacade->getCheckedCartWithModifications($cart);
@@ -93,9 +95,10 @@ public function createOrderMutation(Argument $argument, InputValidator $validato
9395

9496
/**
9597
* @param \Overblog\GraphQLBundle\Definition\Argument $argument
98+
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser|null $currentCustomerUser
9699
* @return string[]
97100
*/
98-
protected function computeValidationGroups(Argument $argument): array
101+
protected function computeValidationGroups(Argument $argument, ?CustomerUser $currentCustomerUser): array
99102
{
100103
$input = $argument['input'];
101104
$validationGroups = ['Default'];
@@ -108,6 +111,10 @@ protected function computeValidationGroups(Argument $argument): array
108111
$validationGroups[] = self::VALIDATION_GROUP_IS_DELIVERY_ADDRESS_DIFFERENT_FROM_BILLING_WITHOUT_PRESELECTED;
109112
}
110113

114+
if ($currentCustomerUser === null) {
115+
$validationGroups[] = self::VALIDATION_GROUP_ANONYMOUS_USER;
116+
}
117+
111118
return $validationGroups;
112119
}
113120
}

src/Resources/config/graphql-types/ModelType/Order/Input/OrderInputDecorator.types.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ OrderInputDecorator:
3333
max: 100
3434
maxMessage: "Last name cannot be longer than {{ limit }} characters"
3535
email:
36-
type: "String!"
36+
type: "String"
3737
description: "The customer's email address"
3838
validation:
3939
- NotBlank:
4040
message: "Please enter email"
41+
groups: "anonymousUser"
4142
- Email:
4243
message: "Please enter valid email"
44+
groups: "anonymousUser"
4345
- Length:
4446
max: 255
4547
maxMessage: "Email cannot be longer than {{ limit }} characters"
48+
groups: "anonymousUser"
4649
telephone:
4750
type: "String!"
4851
description: "The customer's phone number"

0 commit comments

Comments
 (0)