Skip to content

Commit d0d67d4

Browse files
AC-6695: Guest Checkout Fix
1 parent e102b6e commit d0d67d4

File tree

5 files changed

+106
-27
lines changed

5 files changed

+106
-27
lines changed

app/code/Magento/Customer/Api/AccountManagementInterface.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface AccountManagementInterface
3333
* @param string $password
3434
* @param string $redirectUrl
3535
* @return \Magento\Customer\Api\Data\CustomerInterface
36-
* @throws LocalizedException
36+
* @throws \Magento\Framework\Exception\LocalizedException
3737
*/
3838
public function createAccount(
3939
\Magento\Customer\Api\Data\CustomerInterface $customer,
@@ -51,7 +51,7 @@ public function createAccount(
5151
* @return \Magento\Customer\Api\Data\CustomerInterface
5252
* @throws \Magento\Framework\Exception\InputException If bad input is provided
5353
* @throws \Magento\Framework\Exception\State\InputMismatchException If the provided email is already used
54-
* @throws LocalizedException
54+
* @throws \Magento\Framework\Exception\LocalizedException
5555
*/
5656
public function createAccountWithPasswordHash(
5757
\Magento\Customer\Api\Data\CustomerInterface $customer,
@@ -64,7 +64,7 @@ public function createAccountWithPasswordHash(
6464
*
6565
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
6666
* @return \Magento\Customer\Api\Data\ValidationResultsInterface
67-
* @throws LocalizedException
67+
* @throws \Magento\Framework\Exception\LocalizedException
6868
*/
6969
public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer);
7070

@@ -74,7 +74,7 @@ public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer)
7474
* @param int $customerId
7575
* @return bool
7676
* @throws \Magento\Framework\Exception\NoSuchEntityException If group is not found
77-
* @throws LocalizedException
77+
* @throws \Magento\Framework\Exception\LocalizedException
7878
*/
7979
public function isReadonly($customerId);
8080

@@ -84,7 +84,7 @@ public function isReadonly($customerId);
8484
* @param string $email
8585
* @param string $confirmationKey
8686
* @return \Magento\Customer\Api\Data\CustomerInterface
87-
* @throws LocalizedException
87+
* @throws \Magento\Framework\Exception\LocalizedException
8888
*/
8989
public function activate($email, $confirmationKey);
9090

@@ -94,7 +94,7 @@ public function activate($email, $confirmationKey);
9494
* @param int $customerId
9595
* @param string $confirmationKey
9696
* @return \Magento\Customer\Api\Data\CustomerInterface
97-
* @throws LocalizedException
97+
* @throws \Magento\Framework\Exception\LocalizedException
9898
*/
9999
public function activateById($customerId, $confirmationKey);
100100

@@ -104,7 +104,7 @@ public function activateById($customerId, $confirmationKey);
104104
* @param string $email
105105
* @param string $password
106106
* @return \Magento\Customer\Api\Data\CustomerInterface
107-
* @throws LocalizedException
107+
* @throws \Magento\Framework\Exception\LocalizedException
108108
*/
109109
public function authenticate($email, $password);
110110

@@ -115,7 +115,7 @@ public function authenticate($email, $password);
115115
* @param string $currentPassword
116116
* @param string $newPassword
117117
* @return bool true on success
118-
* @throws LocalizedException
118+
* @throws \Magento\Framework\Exception\LocalizedException
119119
*/
120120
public function changePassword($email, $currentPassword, $newPassword);
121121

@@ -126,7 +126,7 @@ public function changePassword($email, $currentPassword, $newPassword);
126126
* @param string $currentPassword
127127
* @param string $newPassword
128128
* @return bool true on success
129-
* @throws LocalizedException
129+
* @throws \Magento\Framework\Exception\LocalizedException
130130
*/
131131
public function changePasswordById($customerId, $currentPassword, $newPassword);
132132

@@ -137,7 +137,7 @@ public function changePasswordById($customerId, $currentPassword, $newPassword);
137137
* @param string $template
138138
* @param int $websiteId
139139
* @return bool true on success
140-
* @throws LocalizedException
140+
* @throws \Magento\Framework\Exception\LocalizedException
141141
*/
142142
public function initiatePasswordReset($email, $template, $websiteId = null);
143143

@@ -150,7 +150,7 @@ public function initiatePasswordReset($email, $template, $websiteId = null);
150150
* @param string $newPassword
151151
*
152152
* @return bool true on success
153-
* @throws LocalizedException
153+
* @throws \Magento\Framework\Exception\LocalizedException
154154
* @throws InputException
155155
*/
156156
public function resetPassword($email, $resetToken, $newPassword);
@@ -167,7 +167,7 @@ public function resetPassword($email, $resetToken, $newPassword);
167167
* @throws \Magento\Framework\Exception\State\ExpiredException If token is expired
168168
* @throws \Magento\Framework\Exception\InputException If token or customer id is invalid
169169
* @throws \Magento\Framework\Exception\NoSuchEntityException If customer doesn't exist
170-
* @throws LocalizedException
170+
* @throws \Magento\Framework\Exception\LocalizedException
171171
*/
172172
public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkToken);
173173

@@ -176,7 +176,7 @@ public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkTo
176176
*
177177
* @param int $customerId
178178
* @return string
179-
* @throws LocalizedException
179+
* @throws \Magento\Framework\Exception\LocalizedException
180180
*/
181181
public function getConfirmationStatus($customerId);
182182

@@ -187,7 +187,7 @@ public function getConfirmationStatus($customerId);
187187
* @param int $websiteId
188188
* @param string $redirectUrl
189189
* @return bool true on success
190-
* @throws LocalizedException
190+
* @throws \Magento\Framework\Exception\LocalizedException
191191
*/
192192
public function resendConfirmation($email, $websiteId, $redirectUrl = '');
193193

@@ -207,7 +207,7 @@ public function isEmailAvailable(string $customerEmail, int $websiteId = null):
207207
* @param int $customerWebsiteId
208208
* @param int $storeId
209209
* @return bool
210-
* @throws LocalizedException
210+
* @throws \Magento\Framework\Exception\LocalizedException
211211
*/
212212
public function isCustomerInStore($customerWebsiteId, $storeId);
213213

@@ -217,7 +217,7 @@ public function isCustomerInStore($customerWebsiteId, $storeId);
217217
* @param int $customerId
218218
* @return \Magento\Customer\Api\Data\AddressInterface
219219
* @throws \Magento\Framework\Exception\NoSuchEntityException If the customer Id is invalid
220-
* @throws LocalizedException
220+
* @throws \Magento\Framework\Exception\LocalizedException
221221
*/
222222
public function getDefaultBillingAddress($customerId);
223223

@@ -227,7 +227,7 @@ public function getDefaultBillingAddress($customerId);
227227
* @param int $customerId
228228
* @return \Magento\Customer\Api\Data\AddressInterface
229229
* @throws \Magento\Framework\Exception\NoSuchEntityException If the customer Id is invalid
230-
* @throws LocalizedException
230+
* @throws \Magento\Framework\Exception\LocalizedException
231231
*/
232232
public function getDefaultShippingAddress($customerId);
233233

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AccountManagement implements AccountManagementInterface
7272
/**
7373
* System Configuration Path for Enable/Disable Login at Guest Checkout
7474
*/
75-
private const GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG = 'checkout/options/enable_guest_checkout_login';
75+
public const GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG = 'checkout/options/enable_guest_checkout_login';
7676

7777
/**
7878
* Configuration paths for create account email template

dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
use Magento\Customer\Api\Data\CustomerInterface as Customer;
1010
use Magento\Customer\Model\AccountManagement;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\Exception\InputException;
1214
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
1315
use Magento\Newsletter\Model\Subscriber;
1416
use Magento\Security\Model\Config;
17+
use Magento\Store\Model\ScopeInterface;
1518
use Magento\TestFramework\Helper\Bootstrap;
1619
use Magento\TestFramework\Helper\Customer as CustomerHelper;
1720
use Magento\TestFramework\TestCase\WebapiAbstract;
@@ -23,15 +26,20 @@
2326
*/
2427
class AccountManagementTest extends WebapiAbstract
2528
{
26-
const SERVICE_VERSION = 'V1';
27-
const SERVICE_NAME = 'customerAccountManagementV1';
28-
const RESOURCE_PATH = '/V1/customers';
29+
public const SERVICE_VERSION = 'V1';
30+
public const SERVICE_NAME = 'customerAccountManagementV1';
31+
public const RESOURCE_PATH = '/V1/customers';
2932

3033
/**
3134
* Sample values for testing
3235
*/
33-
const ATTRIBUTE_CODE = 'attribute_code';
34-
const ATTRIBUTE_VALUE = 'attribute_value';
36+
public const ATTRIBUTE_CODE = 'attribute_code';
37+
public const ATTRIBUTE_VALUE = 'attribute_value';
38+
39+
/**
40+
* @var ObjectManager
41+
*/
42+
private $objectManager;
3543

3644
/**
3745
* @var AccountManagementInterface
@@ -86,6 +94,8 @@ class AccountManagementTest extends WebapiAbstract
8694
*/
8795
protected function setUp(): void
8896
{
97+
$this->objectManager = Bootstrap::getObjectManager();
98+
8999
$this->accountManagement = Bootstrap::getObjectManager()->get(
90100
\Magento\Customer\Api\AccountManagementInterface::class
91101
);
@@ -645,6 +655,7 @@ public function testIsReadonly()
645655

646656
public function testEmailAvailable()
647657
{
658+
$config = $this->objectManager->get(ScopeConfigInterface::class);
648659
$customerData = $this->_createCustomer();
649660

650661
$serviceInfo = [
@@ -662,7 +673,18 @@ public function testEmailAvailable()
662673
'customerEmail' => $customerData[Customer::EMAIL],
663674
'websiteId' => $customerData[Customer::WEBSITE_ID],
664675
];
665-
$this->assertFalse($this->_webApiCall($serviceInfo, $requestData));
676+
677+
$emailSetting = $config->getValue(
678+
AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
679+
ScopeInterface::SCOPE_WEBSITE,
680+
$customerData[Customer::WEBSITE_ID]
681+
);
682+
683+
if (!$emailSetting) {
684+
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
685+
} else {
686+
$this->assertFalse($this->_webApiCall($serviceInfo, $requestData));
687+
}
666688
}
667689

668690
public function testEmailAvailableInvalidEmail()

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/IsEmailAvailableTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,37 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Magento\Customer\Model\AccountManagement;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Store\Api\StoreResolverInterface;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
1015
use Magento\TestFramework\TestCase\GraphQlAbstract;
1116

1217
/**
1318
* Test email availability functionality
1419
*/
1520
class IsEmailAvailableTest extends GraphQlAbstract
1621
{
22+
/**
23+
* @var ScopeConfigInterface
24+
*/
25+
private ScopeConfigInterface $scopeConfig;
26+
27+
/**
28+
* @var string
29+
*/
30+
private string $storeId;
31+
32+
public function setUp(): void
33+
{
34+
$objectManager = Bootstrap::getObjectManager();
35+
$this->scopeConfig = $objectManager->get(ScopeConfigInterface::class);
36+
/* @var StoreResolverInterface $storeResolver */
37+
$storeResolver = $objectManager->get(StoreResolverInterface::class);
38+
$this->storeId = $storeResolver->getCurrentStoreId();
39+
}
40+
1741
/**
1842
* @magentoApiDataFixture Magento/Customer/_files/customer.php
1943
*/
@@ -31,7 +55,16 @@ public function testEmailNotAvailable()
3155

3256
self::assertArrayHasKey('isEmailAvailable', $response);
3357
self::assertArrayHasKey('is_email_available', $response['isEmailAvailable']);
34-
self::assertFalse($response['isEmailAvailable']['is_email_available']);
58+
$emailConfig = $this->scopeConfig->getValue(
59+
AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
60+
ScopeInterface::SCOPE_STORE,
61+
$this->storeId
62+
);
63+
if (!$emailConfig) {
64+
self::assertTrue($response['isEmailAvailable']['is_email_available']);
65+
} else {
66+
self::assertFalse($response['isEmailAvailable']['is_email_available']);
67+
}
3568
}
3669

3770
/**

dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Magento\Customer\Api\AccountManagementInterface;
1010
use Magento\Customer\Api\AddressRepositoryInterface;
1111
use Magento\Customer\Api\Data\AddressInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\Framework\Exception\InputException;
1314
use Magento\Framework\Exception\NoSuchEntityException;
1415
use Magento\Framework\Exception\State\ExpiredException;
1516
use Magento\Framework\Reflection\DataObjectProcessor;
1617
use Magento\Framework\Session\SessionManagerInterface;
1718
use Magento\Framework\Stdlib\DateTime;
1819
use Magento\Framework\Url as UrlBuilder;
20+
use Magento\Store\Model\ScopeInterface;
1921
use Magento\Store\Model\StoreManagerInterface;
2022
use Magento\TestFramework\Helper\Bootstrap;
2123

@@ -604,15 +606,37 @@ public function testResendConfirmationNotNeeded()
604606
*/
605607
public function testIsEmailAvailable()
606608
{
607-
$this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com', 1));
609+
$scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
610+
$guestLoginConfig = $scopeConfig->getValue(
611+
AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
612+
ScopeInterface::SCOPE_WEBSITE,
613+
1
614+
);
615+
616+
if (!$guestLoginConfig) {
617+
$this->assertTrue($this->accountManagement->isEmailAvailable('customer@example.com', 1));
618+
} else {
619+
$this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com', 1));
620+
}
608621
}
609622

610623
/**
611624
* @magentoDataFixture Magento/Customer/_files/customer.php
612625
*/
613626
public function testIsEmailAvailableNoWebsiteSpecified()
614627
{
615-
$this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com'));
628+
$scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
629+
$guestLoginConfig = $scopeConfig->getValue(
630+
AccountManagement::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
631+
ScopeInterface::SCOPE_WEBSITE,
632+
1
633+
);
634+
635+
if (!$guestLoginConfig) {
636+
$this->assertTrue($this->accountManagement->isEmailAvailable('customer@example.com'));
637+
} else {
638+
$this->assertFalse($this->accountManagement->isEmailAvailable('customer@example.com'));
639+
}
616640
}
617641

618642
/**

0 commit comments

Comments
 (0)