Skip to content

Commit 568c7bf

Browse files
cia-2.4.7-beta1-develop-bugfixes-02162023
Merge branch 'AC-6695' into cia-2.4.7-beta1-develop-bugfixes-02162023
2 parents 36968e0 + 7252681 commit 568c7bf

File tree

7 files changed

+120
-14
lines changed

7 files changed

+120
-14
lines changed

app/code/Magento/Checkout/etc/adminhtml/system.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
<resource>Magento_Checkout::checkout</resource>
1414
<group id="options" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
1515
<label>Checkout Options</label>
16+
<field id="enable_guest_checkout_login" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
17+
<label>Enable Guest Checkout Login</label>
18+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
19+
<comment>Enabling this setting will allow unauthenticated users to query if an e-mail address is already associated with a customer account. This can be used to enhance the checkout workflow for guests that do not realize they already have an account but comes at the cost of exposing information to unauthenticated users.</comment>
20+
</field>
1621
<field id="onepage_checkout_enabled" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
1722
<label>Enable Onepage Checkout</label>
1823
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
@@ -23,7 +28,7 @@
2328
</field>
2429
<field id="display_billing_address_on" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
2530
<label>Display Billing Address On</label>
26-
<source_model>\Magento\Checkout\Model\Adminhtml\BillingAddressDisplayOptions</source_model>
31+
<source_model>Magento\Checkout\Model\Adminhtml\BillingAddressDisplayOptions</source_model>
2732
</field>
2833
<field id="max_items_display_count" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
2934
<label>Maximum Number of Items to Display in Order Summary</label>

app/code/Magento/Checkout/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<default>
1010
<checkout>
1111
<options>
12+
<enable_guest_checkout_login>0</enable_guest_checkout_login>
1213
<onepage_checkout_enabled>1</onepage_checkout_enabled>
1314
<guest_checkout>1</guest_checkout>
1415
<display_billing_address_on>0</display_billing_address_on>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Customer\Api;
99

1010
use Magento\Framework\Exception\InputException;
11+
use Magento\Framework\Exception\LocalizedException;
1112

1213
/**
1314
* Interface for managing customers accounts.
@@ -194,7 +195,7 @@ public function resendConfirmation($email, $websiteId, $redirectUrl = '');
194195
* Check if given email is associated with a customer account in given website.
195196
*
196197
* @param string $customerEmail
197-
* @param int $websiteId If not set, will use the current websiteId
198+
* @param int|null $websiteId If not set, will use the current websiteId
198199
* @return bool
199200
* @throws \Magento\Framework\Exception\LocalizedException
200201
*/

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Customer\Model\Customer as CustomerModel;
2121
use Magento\Customer\Model\Customer\CredentialsValidator;
2222
use Magento\Customer\Model\ForgotPasswordToken\GetCustomerByToken;
23+
use Magento\Customer\Model\Logger as CustomerLogger;
2324
use Magento\Customer\Model\Metadata\Validator;
2425
use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory;
2526
use Magento\Directory\Model\AllowedCountries;
@@ -57,7 +58,6 @@
5758
use Magento\Store\Model\ScopeInterface;
5859
use Magento\Store\Model\StoreManagerInterface;
5960
use Psr\Log\LoggerInterface as PsrLogger;
60-
use Magento\Customer\Model\Logger as CustomerLogger;
6161

6262
/**
6363
* Handle various customer account actions
@@ -69,6 +69,11 @@
6969
*/
7070
class AccountManagement implements AccountManagementInterface
7171
{
72+
/**
73+
* System Configuration Path for Enable/Disable Login at Guest Checkout
74+
*/
75+
public const GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG = 'checkout/options/enable_guest_checkout_login';
76+
7277
/**
7378
* Configuration paths for create account email template
7479
*
@@ -719,7 +724,7 @@ private function handleUnknownTemplate($template)
719724
throw new InputException(
720725
__(
721726
'Invalid value of "%value" provided for the %fieldName field. '
722-
. 'Possible values: %template1 or %template2.',
727+
. 'Possible values: %template1 or %template2.',
723728
[
724729
'value' => $template,
725730
'fieldName' => 'template',
@@ -1125,7 +1130,7 @@ public function validate(CustomerInterface $customer)
11251130
$result = $this->eavValidator->isValid($customerModel);
11261131
if ($result === false && is_array($this->eavValidator->getMessages())) {
11271132
return $validationResults->setIsValid(false)->setMessages(
1128-
// phpcs:ignore Magento2.Functions.DiscouragedFunction
1133+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
11291134
call_user_func_array(
11301135
'array_merge',
11311136
array_values($this->eavValidator->getMessages())
@@ -1137,9 +1142,24 @@ public function validate(CustomerInterface $customer)
11371142

11381143
/**
11391144
* @inheritdoc
1145+
*
1146+
* @param string $customerEmail
1147+
* @param int|null $websiteId
1148+
* @return bool
1149+
* @throws LocalizedException
11401150
*/
11411151
public function isEmailAvailable($customerEmail, $websiteId = null)
11421152
{
1153+
$guestLoginConfig = $this->scopeConfig->getValue(
1154+
self::GUEST_CHECKOUT_LOGIN_OPTION_SYS_CONFIG,
1155+
ScopeInterface::SCOPE_WEBSITE,
1156+
$websiteId
1157+
);
1158+
1159+
if (!$guestLoginConfig) {
1160+
return true;
1161+
}
1162+
11431163
try {
11441164
if ($websiteId === null) {
11451165
$websiteId = $this->storeManager->getStore()->getWebsiteId();

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)