diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetGuestEmailOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetGuestEmailOnCart.php index 202b4f84d70f..d621057348b5 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetGuestEmailOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetGuestEmailOnCart.php @@ -32,16 +32,24 @@ class SetGuestEmailOnCart implements ResolverInterface */ private $getCartForUser; + /** + * @var EmailAddressValidator + */ + private $emailValidator; + /** * @param GetCartForUser $getCartForUser * @param CartRepositoryInterface $cartRepository + * @param EmailAddressValidator $emailValidator */ public function __construct( GetCartForUser $getCartForUser, - CartRepositoryInterface $cartRepository + CartRepositoryInterface $cartRepository, + EmailAddressValidator $emailValidator ) { $this->getCartForUser = $getCartForUser; $this->cartRepository = $cartRepository; + $this->emailValidator = $emailValidator; } /** @@ -58,11 +66,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('Required parameter "email" is missing')); } - $guestEmail = $args['input']['email']; - - if (!\Zend_Validate::is($guestEmail, EmailAddressValidator::class)) { + if (false === $this->emailValidator->isValid($args['input']['email'])) { throw new GraphQlInputException(__('Invalid email format')); } + $email = $args['input']['email']; $currentUserId = $context->getUserId(); @@ -71,7 +78,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $cart = $this->getCartForUser->execute($maskedCartId, $currentUserId); - $cart->setCustomerEmail($guestEmail); + $cart->setCustomerEmail($email); try { $this->cartRepository->save($cart); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetGuestEmailOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetGuestEmailOnCartTest.php index 57b734eaa027..a4a84c2f8c74 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetGuestEmailOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetGuestEmailOnCartTest.php @@ -83,7 +83,7 @@ private function getQuery(string $maskedQuoteId, string $email): string email: "$email" }) { cart { - guest_email + email } } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetGuestEmailOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetGuestEmailOnCartTest.php index 5aefa510d745..b877dccdeba3 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetGuestEmailOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetGuestEmailOnCartTest.php @@ -40,7 +40,7 @@ public function testSetGuestEmailOnCart() $this->assertArrayHasKey('setGuestEmailOnCart', $response); $this->assertArrayHasKey('cart', $response['setGuestEmailOnCart']); - $this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['guest_email']); + $this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['email']); } /** @@ -65,16 +65,14 @@ public function testSetGuestEmailOnCustomerCart() * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * * @dataProvider incorrectEmailDataProvider - * @param string $maskedQuoteId * @param string $email * @param string $exceptionMessage */ public function testSetGuestEmailOnCartWithIncorrectEmail( - string $maskedQuoteId, string $email, string $exceptionMessage ) { - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($maskedQuoteId); + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); $query = $this->getQuery($maskedQuoteId, $email); $this->expectExceptionMessage($exceptionMessage); @@ -87,8 +85,8 @@ public function testSetGuestEmailOnCartWithIncorrectEmail( public function incorrectEmailDataProvider(): array { return [ - 'wrong_email' => ['test_quote', 'some', 'Invalid email format'], - 'no_email' => ['test_quote', '', 'Required parameter "email" is missing'], + 'wrong_email' => ['some', 'Invalid email format'], + 'no_email' => ['', 'Required parameter "email" is missing'], ]; } @@ -134,7 +132,7 @@ private function getQuery(string $maskedQuoteId, string $email): string email: "$email" }) { cart { - guest_email + email } } }