Skip to content
Snippets Groups Projects
Commit f1e6d1c9 authored by Oleksii Korshenko's avatar Oleksii Korshenko Committed by GitHub
Browse files

Merge pull request #1596 from magento-engcom/2.2-develop-prs

Public Pull Requests

magento/magento2#11437 Add confirmation and lock_expires to customer export csv - Fix issue 10765 by @convenient
parents 190a4a43 4bad8825
No related merge requests found
...@@ -13,6 +13,8 @@ use Magento\Customer\Api\GroupRepositoryInterface; ...@@ -13,6 +13,8 @@ use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Ui\Component\DataProvider\Document; use Magento\Customer\Ui\Component\DataProvider\Document;
use Magento\Framework\Api\AttributeValue; use Magento\Framework\Api\AttributeValue;
use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Phrase;
use Magento\Store\Api\Data\WebsiteInterface; use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\StoreManagerInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject; use PHPUnit_Framework_MockObject_MockObject as MockObject;
...@@ -44,6 +46,11 @@ class DocumentTest extends \PHPUnit\Framework\TestCase ...@@ -44,6 +46,11 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
*/ */
private $storeManager; private $storeManager;
/**
* @var ScopeConfigInterface|MockObject
*/
private $scopeConfig;
/** /**
* @var Document * @var Document
*/ */
...@@ -59,11 +66,14 @@ class DocumentTest extends \PHPUnit\Framework\TestCase ...@@ -59,11 +66,14 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
$this->scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$this->document = new Document( $this->document = new Document(
$this->attributeValueFactory, $this->attributeValueFactory,
$this->groupRepository, $this->groupRepository,
$this->customerMetadata, $this->customerMetadata,
$this->storeManager $this->storeManager,
$this->scopeConfig
); );
} }
...@@ -156,6 +166,41 @@ class DocumentTest extends \PHPUnit\Framework\TestCase ...@@ -156,6 +166,41 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
static::assertEquals('Main Website', $attribute->getValue()); static::assertEquals('Main Website', $attribute->getValue());
} }
/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetConfirmationAttribute()
{
$websiteId = 1;
$this->document->setData('original_website_id', $websiteId);
$this->scopeConfig->expects(static::once())
->method('getValue')
->with()
->willReturn(true);
$this->document->setData('confirmation', null);
$attribute = $this->document->getCustomAttribute('confirmation');
$value = $attribute->getValue();
static::assertInstanceOf(Phrase::class, $value);
static::assertEquals('Confirmed', (string)$value);
}
/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetAccountLockValue()
{
$this->document->setData('lock_expires', null);
$attribute = $this->document->getCustomAttribute('lock_expires');
$value = $attribute->getValue();
static::assertInstanceOf(Phrase::class, $value);
static::assertEquals('Unlocked', (string)$value);
}
/** /**
* Create mock for attribute value factory * Create mock for attribute value factory
* @return void * @return void
......
...@@ -6,9 +6,13 @@ ...@@ -6,9 +6,13 @@
namespace Magento\Customer\Ui\Component\DataProvider; namespace Magento\Customer\Ui\Component\DataProvider;
use Magento\Customer\Api\CustomerMetadataInterface; use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Model\AccountManagement;
use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\StoreManagerInterface;
/** /**
...@@ -31,6 +35,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ ...@@ -31,6 +35,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
*/ */
private static $websiteAttributeCode = 'website_id'; private static $websiteAttributeCode = 'website_id';
/**
* @var string
*/
private static $websiteIdAttributeCode = 'original_website_id';
/**
* @var string
*/
private static $confirmationAttributeCode = 'confirmation';
/**
* @var string
*/
private static $accountLockAttributeCode = 'lock_expires';
/** /**
* @var CustomerMetadataInterface * @var CustomerMetadataInterface
*/ */
...@@ -46,23 +65,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ ...@@ -46,23 +65,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
*/ */
private $storeManager; private $storeManager;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/** /**
* Document constructor. * Document constructor.
* @param AttributeValueFactory $attributeValueFactory * @param AttributeValueFactory $attributeValueFactory
* @param GroupRepositoryInterface $groupRepository * @param GroupRepositoryInterface $groupRepository
* @param CustomerMetadataInterface $customerMetadata * @param CustomerMetadataInterface $customerMetadata
* @param StoreManagerInterface $storeManager * @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
*/ */
public function __construct( public function __construct(
AttributeValueFactory $attributeValueFactory, AttributeValueFactory $attributeValueFactory,
GroupRepositoryInterface $groupRepository, GroupRepositoryInterface $groupRepository,
CustomerMetadataInterface $customerMetadata, CustomerMetadataInterface $customerMetadata,
StoreManagerInterface $storeManager StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig = null
) { ) {
parent::__construct($attributeValueFactory); parent::__construct($attributeValueFactory);
$this->customerMetadata = $customerMetadata; $this->customerMetadata = $customerMetadata;
$this->groupRepository = $groupRepository; $this->groupRepository = $groupRepository;
$this->storeManager = $storeManager; $this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->create(ScopeConfigInterface::class);
} }
/** /**
...@@ -80,6 +107,12 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ ...@@ -80,6 +107,12 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
case self::$websiteAttributeCode: case self::$websiteAttributeCode:
$this->setWebsiteValue(); $this->setWebsiteValue();
break; break;
case self::$confirmationAttributeCode:
$this->setConfirmationValue();
break;
case self::$accountLockAttributeCode:
$this->setAccountLockValue();
break;
} }
return parent::getCustomAttribute($attributeCode); return parent::getCustomAttribute($attributeCode);
} }
...@@ -133,5 +166,49 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ ...@@ -133,5 +166,49 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
$value = $this->getData(self::$websiteAttributeCode); $value = $this->getData(self::$websiteAttributeCode);
$list = $this->storeManager->getWebsites(); $list = $this->storeManager->getWebsites();
$this->setCustomAttribute(self::$websiteAttributeCode, $list[$value]->getName()); $this->setCustomAttribute(self::$websiteAttributeCode, $list[$value]->getName());
$this->setCustomAttribute(self::$websiteIdAttributeCode, $value);
}
/**
* Update confirmation value
* Method set confirmation text value to match what is shown in grid
* @return void
*/
private function setConfirmationValue()
{
$value = $this->getData(self::$confirmationAttributeCode);
$websiteId = $this->getData(self::$websiteIdAttributeCode) ?: $this->getData(self::$websiteAttributeCode);
$isConfirmRequired = (bool)$this->scopeConfig->getValue(
AccountManagement::XML_PATH_IS_CONFIRM,
ScopeInterface::SCOPE_WEBSITES,
$websiteId
);
$valueText = __('Confirmation Not Required');
if ($isConfirmRequired) {
$valueText = $value === null ? __('Confirmed') : __('Confirmation Required');
}
$this->setCustomAttribute(self::$confirmationAttributeCode, $valueText);
}
/**
* Update lock expires value
* Method set account lock text value to match what is shown in grid
* @return void
*/
private function setAccountLockValue()
{
$value = $this->getDataByPath(self::$accountLockAttributeCode);
$valueText = __('Unlocked');
if ($value !== null) {
$lockExpires = new \DateTime($value);
if ($lockExpires > new \DateTime()) {
$valueText = __('Locked');
}
}
$this->setCustomAttribute(self::$accountLockAttributeCode, $valueText);
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment