From 8573467f9f40c76d362b5992e70de9f7cd8782ed Mon Sep 17 00:00:00 2001 From: Derrick Heesbeen Date: Mon, 30 Oct 2017 15:29:05 +0000 Subject: [PATCH 1/2] [BUGFIX] Made method public so a plugin is possible. --- app/code/Magento/Customer/Model/AccountManagement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index b7b099ec45232..f6c8366ae1a73 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -1127,7 +1127,7 @@ protected function sendEmailTemplate( * @param CustomerInterface $customer * @return bool */ - protected function isConfirmationRequired($customer) + public function isConfirmationRequired($customer) { if ($this->canSkipConfirmation($customer)) { return false; From 6227a14c301604008e4b62e061fdc482f6b66371 Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Tue, 5 Dec 2017 16:10:54 +0200 Subject: [PATCH 2/2] [BUGFIX] Made method public so a plugin is possible. --- .../Customer/Model/AccountConfirmation.php | 89 ++++++++++++++++++ .../Customer/Model/AccountManagement.php | 35 ++++--- app/code/Magento/Customer/Model/Customer.php | 30 ++++-- .../Unit/Model/AccountConfirmationTest.php | 93 +++++++++++++++++++ .../Test/Unit/Model/AccountManagementTest.php | 35 +++---- .../Customer/Test/Unit/Model/CustomerTest.php | 39 ++++---- .../Listing/Column/ConfirmationTest.php | 24 +++-- .../Component/Listing/Column/Confirmation.php | 44 +++++---- 8 files changed, 302 insertions(+), 87 deletions(-) create mode 100644 app/code/Magento/Customer/Model/AccountConfirmation.php create mode 100644 app/code/Magento/Customer/Test/Unit/Model/AccountConfirmationTest.php diff --git a/app/code/Magento/Customer/Model/AccountConfirmation.php b/app/code/Magento/Customer/Model/AccountConfirmation.php new file mode 100644 index 0000000000000..7d01ff0efc411 --- /dev/null +++ b/app/code/Magento/Customer/Model/AccountConfirmation.php @@ -0,0 +1,89 @@ +scopeConfig = $scopeConfig; + $this->registry = $registry; + } + + /** + * Check if accounts confirmation is required. + * + * @param int|null $websiteId + * @param int|null $customerId + * @param string $customerEmail + * @return bool + */ + public function isConfirmationRequired($websiteId, $customerId, $customerEmail): bool + { + if ($this->canSkipConfirmation($customerId, $customerEmail)) { + return false; + } + + return (bool)$this->scopeConfig->getValue( + self::XML_PATH_IS_CONFIRM, + ScopeInterface::SCOPE_WEBSITES, + $websiteId + ); + } + + /** + * Check whether confirmation may be skipped when registering using certain email address. + * + * @param int|null $customerId + * @param string $customerEmail + * @return bool + */ + private function canSkipConfirmation($customerId, $customerEmail): bool + { + if (!$customerId) { + return false; + } + + /* If an email was used to start the registration process and it is the same email as the one + used to register, then this can skip confirmation. + */ + $skipConfirmationIfEmail = $this->registry->registry("skip_confirmation_if_email"); + if (!$skipConfirmationIfEmail) { + return false; + } + + return strtolower($skipConfirmationIfEmail) === strtolower($customerEmail); + } +} diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 03bf6361be72c..27ca2bc6bf6a3 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -89,6 +89,10 @@ class AccountManagement implements AccountManagementInterface */ const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity'; + /** + * @deprecated + * @see AccountConfirmation::XML_PATH_IS_CONFIRM + */ const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm'; /** @@ -298,6 +302,11 @@ class AccountManagement implements AccountManagementInterface */ private $dateTimeFactory; + /** + * @var AccountConfirmation + */ + private $accountConfirmation; + /** * @param CustomerFactory $customerFactory * @param ManagerInterface $eventManager @@ -323,7 +332,8 @@ class AccountManagement implements AccountManagementInterface * @param ObjectFactory $objectFactory * @param ExtensibleDataObjectConverter $extensibleDataObjectConverter * @param CredentialsValidator|null $credentialsValidator - * @param DateTimeFactory $dateTimeFactory + * @param DateTimeFactory|null $dateTimeFactory + * @param AccountConfirmation|null $accountConfirmation * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -351,7 +361,8 @@ public function __construct( ObjectFactory $objectFactory, ExtensibleDataObjectConverter $extensibleDataObjectConverter, CredentialsValidator $credentialsValidator = null, - DateTimeFactory $dateTimeFactory = null + DateTimeFactory $dateTimeFactory = null, + AccountConfirmation $accountConfirmation = null ) { $this->customerFactory = $customerFactory; $this->eventManager = $eventManager; @@ -379,6 +390,8 @@ public function __construct( $this->credentialsValidator = $credentialsValidator ?: ObjectManager::getInstance()->get(CredentialsValidator::class); $this->dateTimeFactory = $dateTimeFactory ?: ObjectManager::getInstance()->get(DateTimeFactory::class); + $this->accountConfirmation = $accountConfirmation ?: ObjectManager::getInstance() + ->get(AccountConfirmation::class); } /** @@ -1147,17 +1160,15 @@ protected function sendEmailTemplate( * * @param CustomerInterface $customer * @return bool + * @deprecated + * @see AccountConfirmation::isConfirmationRequired */ - public function isConfirmationRequired($customer) + protected function isConfirmationRequired($customer) { - if ($this->canSkipConfirmation($customer)) { - return false; - } - - return (bool)$this->scopeConfig->getValue( - self::XML_PATH_IS_CONFIRM, - ScopeInterface::SCOPE_WEBSITES, - $customer->getWebsiteId() + return $this->accountConfirmation->isConfirmationRequired( + $customer->getWebsiteId(), + $customer->getId(), + $customer->getEmail() ); } @@ -1166,6 +1177,8 @@ public function isConfirmationRequired($customer) * * @param CustomerInterface $customer * @return bool + * @deprecated + * @see AccountConfirmation::isConfirmationRequired */ protected function canSkipConfirmation($customer) { diff --git a/app/code/Magento/Customer/Model/Customer.php b/app/code/Magento/Customer/Model/Customer.php index 2e2260f16ff91..e0a7281776de9 100644 --- a/app/code/Magento/Customer/Model/Customer.php +++ b/app/code/Magento/Customer/Model/Customer.php @@ -18,6 +18,7 @@ use Magento\Framework\Indexer\StateInterface; use Magento\Framework\Reflection\DataObjectProcessor; use Magento\Store\Model\ScopeInterface; +use Magento\Framework\App\ObjectManager; /** * Customer model @@ -58,6 +59,10 @@ class Customer extends \Magento\Framework\Model\AbstractModel const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template'; + /** + * @deprecated + * @see AccountConfirmation::XML_PATH_IS_CONFIRM + */ const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm'; const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template'; @@ -208,6 +213,11 @@ class Customer extends \Magento\Framework\Model\AbstractModel */ protected $indexerRegistry; + /** + * @var AccountConfirmation + */ + private $accountConfirmation; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -229,6 +239,7 @@ class Customer extends \Magento\Framework\Model\AbstractModel * @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data + * @param AccountConfirmation|null $accountConfirmation * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -252,7 +263,8 @@ public function __construct( \Magento\Customer\Api\CustomerMetadataInterface $metadataService, \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + AccountConfirmation $accountConfirmation = null ) { $this->metadataService = $metadataService; $this->_scopeConfig = $scopeConfig; @@ -269,6 +281,8 @@ public function __construct( $this->dataObjectProcessor = $dataObjectProcessor; $this->dataObjectHelper = $dataObjectHelper; $this->indexerRegistry = $indexerRegistry; + $this->accountConfirmation = $accountConfirmation ?: ObjectManager::getInstance() + ->get(AccountConfirmation::class); parent::__construct( $context, $registry, @@ -770,20 +784,14 @@ public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeI * Check if accounts confirmation is required in config * * @return bool + * @deprecated + * @see AccountConfirmation::isConfirmationRequired */ public function isConfirmationRequired() { - if ($this->canSkipConfirmation()) { - return false; - } - $websiteId = $this->getWebsiteId() ? $this->getWebsiteId() : null; - return (bool)$this->_scopeConfig->getValue( - self::XML_PATH_IS_CONFIRM, - ScopeInterface::SCOPE_WEBSITES, - $websiteId - ); + return $this->accountConfirmation->isConfirmationRequired($websiteId, $this->getId(), $this->getEmail()); } /** @@ -1156,6 +1164,8 @@ public function setIsReadonly($value) * Check whether confirmation may be skipped when registering using certain email address * * @return bool + * @deprecated + * @see AccountConfirmation::isConfirmationRequired */ protected function canSkipConfirmation() { diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountConfirmationTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountConfirmationTest.php new file mode 100644 index 0000000000000..ae246665b28ed --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Model/AccountConfirmationTest.php @@ -0,0 +1,93 @@ +scopeConfig = $this->createMock(ScopeConfigInterface::class); + $this->registry = $this->createMock(Registry::class); + + $this->accountConfirmation = new AccountConfirmation( + $this->scopeConfig, + $this->registry + ); + } + + /** + * @param $customerId + * @param $customerEmail + * @param $skipConfirmationIfEmail + * @param $isConfirmationEnabled + * @param $expected + * @dataProvider dataProviderIsConfirmationRequired + */ + public function testIsConfirmationRequired( + $customerId, + $customerEmail, + $skipConfirmationIfEmail, + $isConfirmationEnabled, + $expected + ) { + $websiteId = 1; + + $this->scopeConfig->expects($this->any()) + ->method('getValue') + ->with( + $this->accountConfirmation::XML_PATH_IS_CONFIRM, + ScopeInterface::SCOPE_WEBSITES, + $websiteId + )->willReturn($isConfirmationEnabled); + + $this->registry->expects($this->any()) + ->method('registry') + ->with('skip_confirmation_if_email') + ->willReturn($skipConfirmationIfEmail); + + self::assertEquals( + $expected, + $this->accountConfirmation->isConfirmationRequired($websiteId, $customerId, $customerEmail) + ); + } + + /** + * @return array + */ + public function dataProviderIsConfirmationRequired() + { + return [ + [null, 'customer@example.com', null, true, true], + [null, 'customer@example.com', null, false, false], + [1, 'customer@example.com', 'customer@example.com', true, false], + [1, 'customer@example.com', 'customer1@example.com', false, false], + [1, 'customer@example.com', 'customer1@example.com', true, true], + ]; + } +} diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php index 2a6b9fe6fd4ea..fed2005ade8e2 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php @@ -6,6 +6,7 @@ namespace Magento\Customer\Test\Unit\Model; use Magento\Customer\Model\AccountManagement; +use Magento\Customer\Model\AccountConfirmation; use Magento\Customer\Model\AuthenticationInterface; use Magento\Customer\Model\EmailNotificationInterface; use Magento\Framework\App\Area; @@ -120,6 +121,11 @@ class AccountManagementTest extends \PHPUnit\Framework\TestCase */ private $dateTimeFactory; + /** + * @var AccountConfirmation|\PHPUnit_Framework_MockObject_MockObject + */ + private $accountConfirmation; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -170,6 +176,7 @@ protected function setUp() ->getMock(); $this->dateTimeFactory = $this->createMock(DateTimeFactory::class); + $this->accountConfirmation = $this->createMock(AccountConfirmation::class); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->accountManagement = $this->objectManagerHelper->getObject( @@ -199,6 +206,7 @@ protected function setUp() 'objectFactory' => $this->objectFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'dateTimeFactory' => $this->dateTimeFactory, + 'accountConfirmation' => $this->accountConfirmation ] ); $reflection = new \ReflectionClass(get_class($this->accountManagement)); @@ -1467,14 +1475,12 @@ public function testAuthenticate() } /** - * @param string|null $skipConfirmationIfEmail * @param int $isConfirmationRequired * @param string|null $confirmation * @param string $expected * @dataProvider dataProviderGetConfirmationStatus */ public function testGetConfirmationStatus( - $skipConfirmationIfEmail, $isConfirmationRequired, $confirmation, $expected @@ -1492,21 +1498,16 @@ public function testGetConfirmationStatus( $customerMock->expects($this->any()) ->method('getConfirmation') ->willReturn($confirmation); - $customerMock->expects($this->any()) + $customerMock->expects($this->once()) ->method('getEmail') ->willReturn($customerEmail); - $customerMock->expects($this->any()) + $customerMock->expects($this->once()) ->method('getWebsiteId') ->willReturn($websiteId); - $this->registry->expects($this->once()) - ->method('registry') - ->with('skip_confirmation_if_email') - ->willReturn($skipConfirmationIfEmail); - - $this->scopeConfig->expects($this->any()) - ->method('getValue') - ->with(AccountManagement::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId) + $this->accountConfirmation->expects($this->once()) + ->method('isConfirmationRequired') + ->with($websiteId, $customerId, $customerEmail) ->willReturn($isConfirmationRequired); $this->customerRepository->expects($this->once()) @@ -1523,11 +1524,11 @@ public function testGetConfirmationStatus( public function dataProviderGetConfirmationStatus() { return [ - [null, 0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED], - ['test1@example.com', 0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED], - ['test2@example.com', 0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED], - ['test2@example.com', 1, null, AccountManagement::ACCOUNT_CONFIRMED], - ['test2@example.com', 1, 'test', AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED], + [0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED], + [0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED], + [0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED], + [1, null, AccountManagement::ACCOUNT_CONFIRMED], + [1, 'test', AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED], ]; } diff --git a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php index 8b3f7875e3c97..f5b7f08d2906d 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php @@ -12,7 +12,7 @@ namespace Magento\Customer\Test\Unit\Model; use Magento\Customer\Model\Customer; -use Magento\Store\Model\ScopeInterface; +use Magento\Customer\Model\AccountConfirmation; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -63,6 +63,11 @@ class CustomerTest extends \PHPUnit\Framework\TestCase */ private $dataObjectProcessor; + /** + * @var AccountConfirmation|\PHPUnit_Framework_MockObject_MockObject + */ + private $accountConfirmation; + protected function setUp() { $this->_website = $this->createMock(\Magento\Store\Model\Website::class); @@ -94,6 +99,7 @@ protected function setUp() $this->registryMock = $this->createPartialMock(\Magento\Framework\Registry::class, ['registry']); $this->_encryptor = $this->createMock(\Magento\Framework\Encryption\EncryptorInterface::class); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->accountConfirmation = $this->createMock(AccountConfirmation::class); $this->_model = $helper->getObject( \Magento\Customer\Model\Customer::class, [ @@ -105,7 +111,8 @@ protected function setUp() 'attributeFactory' => $this->attributeFactoryMock, 'registry' => $this->registryMock, 'resource' => $this->resourceMock, - 'dataObjectProcessor' => $this->dataObjectProcessor + 'dataObjectProcessor' => $this->dataObjectProcessor, + 'accountConfirmation' => $this->accountConfirmation ] ); } @@ -215,32 +222,27 @@ public function isCustomerLockedDataProvider() /** * @param int $customerId * @param int $websiteId - * @param string|null $skipConfirmationIfEmail + * @param bool $isConfirmationRequired * @param bool $expected * @dataProvider dataProviderIsConfirmationRequired */ public function testIsConfirmationRequired( $customerId, $websiteId, - $skipConfirmationIfEmail, + $isConfirmationRequired, $expected ) { $customerEmail = 'test1@example.com'; - $this->registryMock->expects($this->any()) - ->method('registry') - ->with('skip_confirmation_if_email') - ->willReturn($skipConfirmationIfEmail); - - $this->_scopeConfigMock->expects($this->any()) - ->method('getValue') - ->with(Customer::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId) - ->willReturn($expected); - $this->_model->setData('id', $customerId); $this->_model->setData('website_id', $websiteId); $this->_model->setData('email', $customerEmail); + $this->accountConfirmation->expects($this->once()) + ->method('isConfirmationRequired') + ->with($websiteId, $customerId, $customerEmail) + ->willReturn($isConfirmationRequired); + $this->assertEquals($expected, $this->_model->isConfirmationRequired()); } @@ -250,12 +252,9 @@ public function testIsConfirmationRequired( public function dataProviderIsConfirmationRequired() { return [ - [null, null, null, false], - [1, 1, null, false], - [1, 1, 'test1@example.com', false], - [1, 1, 'test2@example.com', true], - [1, 0, 'test2@example.com', true], - [1, null, 'test2@example.com', true], + [null, null, false, false], + [1, 1, true, true], + [1, null, true, true], ]; } diff --git a/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/ConfirmationTest.php b/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/ConfirmationTest.php index e55cee49b5c94..b712c0f30b430 100644 --- a/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/ConfirmationTest.php +++ b/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/ConfirmationTest.php @@ -5,13 +5,12 @@ */ namespace Magento\Customer\Test\Unit\Ui\Component\Listing\Column; -use Magento\Customer\Model\AccountManagement; +use Magento\Customer\Model\AccountConfirmation; use Magento\Customer\Ui\Component\Listing\Column\Confirmation; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Framework\View\Element\UiComponentFactory; -use Magento\Store\Model\ScopeInterface; class ConfirmationTest extends \PHPUnit\Framework\TestCase { @@ -40,6 +39,11 @@ class ConfirmationTest extends \PHPUnit\Framework\TestCase */ protected $processor; + /** + * @var AccountConfirmation|\PHPUnit_Framework_MockObject_MockObject + */ + protected $accountConfirmation; + public function setup() { $this->processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class) @@ -60,12 +64,15 @@ public function setup() $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) ->getMockForAbstractClass(); + $this->accountConfirmation = $this->createMock(AccountConfirmation::class); + $this->confirmation = new Confirmation( $this->context, $this->uiComponentFactory, $this->scopeConfig, [], - [] + [], + $this->accountConfirmation ); } @@ -81,12 +88,17 @@ public function testPrepareDataSource( $expected ) { $websiteId = 1; + $customerId = 1; + $customerEmail = 'customer@example.com'; $dataSource = [ 'data' => [ 'items' => [ [ + 'id_field_name' => 'entity_id', + 'entity_id' => $customerId, 'confirmation' => $confirmation, + 'email' => $customerEmail, 'website_id' => [ $websiteId, ], @@ -100,9 +112,9 @@ public function testPrepareDataSource( ->with($this->confirmation) ->willReturnSelf(); - $this->scopeConfig->expects($this->once()) - ->method('getValue') - ->with(AccountManagement::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId) + $this->accountConfirmation->expects($this->once()) + ->method('isConfirmationRequired') + ->with($websiteId, $customerId, $customerEmail) ->willReturn($isConfirmationRequired); $this->confirmation->setData('name', 'confirmation'); diff --git a/app/code/Magento/Customer/Ui/Component/Listing/Column/Confirmation.php b/app/code/Magento/Customer/Ui/Component/Listing/Column/Confirmation.php index dcaaa665ad392..1786c52844a75 100644 --- a/app/code/Magento/Customer/Ui/Component/Listing/Column/Confirmation.php +++ b/app/code/Magento/Customer/Ui/Component/Listing/Column/Confirmation.php @@ -5,35 +5,42 @@ */ namespace Magento\Customer\Ui\Component\Listing\Column; -use Magento\Customer\Model\AccountManagement; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; -use Magento\Store\Model\ScopeInterface; use Magento\Ui\Component\Listing\Columns\Column; +use Magento\Framework\App\ObjectManager; +use Magento\Customer\Model\AccountConfirmation; +/** + * Class Confirmation column. + */ class Confirmation extends Column { /** - * @var ScopeConfigInterface + * @var AccountConfirmation */ - private $scopeConfig; + private $accountConfirmation; /** * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig @deprecated * @param array $components * @param array $data + * @param AccountConfirmation $accountConfirmation + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, ScopeConfigInterface $scopeConfig, array $components, - array $data + array $data, + AccountConfirmation $accountConfirmation = null ) { - $this->scopeConfig = $scopeConfig; + $this->accountConfirmation = $accountConfirmation ?: ObjectManager::getInstance() + ->get(AccountConfirmation::class); parent::__construct($context, $uiComponentFactory, $components, $data); } @@ -58,7 +65,13 @@ public function prepareDataSource(array $dataSource) */ private function getFieldLabel(array $item) { - if ($this->isConfirmationRequired($item)) { + $isConfirmationRequired = $this->accountConfirmation->isConfirmationRequired( + $item['website_id'][0], + $item[$item['id_field_name']], + $item['email'] + ); + + if ($isConfirmationRequired) { if ($item[$this->getData('name')] === null) { return __('Confirmed'); } @@ -66,19 +79,4 @@ private function getFieldLabel(array $item) } return __('Confirmation Not Required'); } - - /** - * Check if confirmation is required - * - * @param array $item - * @return bool - */ - private function isConfirmationRequired(array $item) - { - return (bool)$this->scopeConfig->getValue( - AccountManagement::XML_PATH_IS_CONFIRM, - ScopeInterface::SCOPE_WEBSITES, - $item['website_id'][0] - ); - } }