66namespace Magento \Customer \Ui \Component \DataProvider ;
77
88use Magento \Customer \Api \CustomerMetadataInterface ;
9+ use Magento \Customer \Model \AccountManagement ;
910use Magento \Framework \Api \AttributeValueFactory ;
11+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1012use Magento \Framework \Exception \NoSuchEntityException ;
1113use Magento \Customer \Api \GroupRepositoryInterface ;
14+ use Magento \Store \Model \ScopeInterface ;
1215use Magento \Store \Model \StoreManagerInterface ;
1316
1417/**
@@ -31,6 +34,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
3134 */
3235 private static $ websiteAttributeCode = 'website_id ' ;
3336
37+ /**
38+ * @var string
39+ */
40+ private static $ websiteIdAttributeCode = 'original_website_id ' ;
41+
42+ /**
43+ * @var string
44+ */
45+ private static $ confirmationAttributeCode = 'confirmation ' ;
46+
47+ /**
48+ * @var string
49+ */
50+ private static $ accountLockAttributeCode = 'lock_expires ' ;
51+
3452 /**
3553 * @var CustomerMetadataInterface
3654 */
@@ -46,23 +64,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
4664 */
4765 private $ storeManager ;
4866
67+ /**
68+ * @var ScopeConfigInterface
69+ */
70+ private $ scopeConfig ;
71+
4972 /**
5073 * Document constructor.
5174 * @param AttributeValueFactory $attributeValueFactory
5275 * @param GroupRepositoryInterface $groupRepository
5376 * @param CustomerMetadataInterface $customerMetadata
5477 * @param StoreManagerInterface $storeManager
78+ * @param ScopeConfigInterface $scopeConfig
5579 */
5680 public function __construct (
5781 AttributeValueFactory $ attributeValueFactory ,
5882 GroupRepositoryInterface $ groupRepository ,
5983 CustomerMetadataInterface $ customerMetadata ,
60- StoreManagerInterface $ storeManager
84+ StoreManagerInterface $ storeManager ,
85+ ScopeConfigInterface $ scopeConfig
6186 ) {
6287 parent ::__construct ($ attributeValueFactory );
6388 $ this ->customerMetadata = $ customerMetadata ;
6489 $ this ->groupRepository = $ groupRepository ;
6590 $ this ->storeManager = $ storeManager ;
91+ $ this ->scopeConfig = $ scopeConfig ;
6692 }
6793
6894 /**
@@ -80,6 +106,12 @@ public function getCustomAttribute($attributeCode)
80106 case self ::$ websiteAttributeCode :
81107 $ this ->setWebsiteValue ();
82108 break ;
109+ case self ::$ confirmationAttributeCode :
110+ $ this ->setConfirmationValue ();
111+ break ;
112+ case self ::$ accountLockAttributeCode :
113+ $ this ->setAccountLockValue ();
114+ break ;
83115 }
84116 return parent ::getCustomAttribute ($ attributeCode );
85117 }
@@ -133,5 +165,47 @@ private function setWebsiteValue()
133165 $ value = $ this ->getData (self ::$ websiteAttributeCode );
134166 $ list = $ this ->storeManager ->getWebsites ();
135167 $ this ->setCustomAttribute (self ::$ websiteAttributeCode , $ list [$ value ]->getName ());
168+ $ this ->setCustomAttribute (self ::$ websiteIdAttributeCode , $ value );
169+ }
170+
171+ /**
172+ * Update confirmation value
173+ * Method set confirmation text value to match what is shown in grid
174+ * @return void
175+ */
176+ private function setConfirmationValue ()
177+ {
178+ $ value = $ this ->getData (self ::$ confirmationAttributeCode );
179+ $ websiteId = $ this ->getData (self ::$ websiteIdAttributeCode ) ?: $ this ->getData (self ::$ websiteAttributeCode );
180+ $ isConfirmationRequired = (bool )$ this ->scopeConfig ->getValue (
181+ AccountManagement::XML_PATH_IS_CONFIRM ,
182+ ScopeInterface::SCOPE_WEBSITES ,
183+ $ websiteId );
184+
185+ $ valueText = !$ isConfirmationRequired ?
186+ __ ('Confirmation Not Required ' )
187+ : ($ value === null ? __ ('Confirmed ' ) : __ ('Confirmation Required ' ));
188+
189+ $ this ->setCustomAttribute (self ::$ confirmationAttributeCode , $ valueText );
190+ }
191+
192+ /**
193+ * Update lock expires value
194+ * Method set account lock text value to match what is shown in grid
195+ * @return void
196+ */
197+ private function setAccountLockValue ()
198+ {
199+ $ value = $ this ->getDataByPath (self ::$ accountLockAttributeCode );
200+
201+ $ valueText = __ ('Unlocked ' );
202+ if ($ value !== null ) {
203+ $ lockExpires = new \DateTime ($ value );
204+ if ($ lockExpires > new \DateTime ()) {
205+ $ valueText = __ ('Locked ' );
206+ }
207+ }
208+
209+ $ this ->setCustomAttribute (self ::$ accountLockAttributeCode , $ valueText );
136210 }
137211}
0 commit comments