6
6
namespace Magento \Customer \Ui \Component \DataProvider ;
7
7
8
8
use Magento \Customer \Api \CustomerMetadataInterface ;
9
+ use Magento \Customer \Model \AccountManagement ;
9
10
use Magento \Framework \Api \AttributeValueFactory ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
10
12
use Magento \Framework \Exception \NoSuchEntityException ;
11
13
use Magento \Customer \Api \GroupRepositoryInterface ;
14
+ use Magento \Framework \App \ObjectManager ;
15
+ use Magento \Store \Model \ScopeInterface ;
12
16
use Magento \Store \Model \StoreManagerInterface ;
13
17
14
18
/**
@@ -31,6 +35,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
31
35
*/
32
36
private static $ websiteAttributeCode = 'website_id ' ;
33
37
38
+ /**
39
+ * @var string
40
+ */
41
+ private static $ websiteIdAttributeCode = 'original_website_id ' ;
42
+
43
+ /**
44
+ * @var string
45
+ */
46
+ private static $ confirmationAttributeCode = 'confirmation ' ;
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ private static $ accountLockAttributeCode = 'lock_expires ' ;
52
+
34
53
/**
35
54
* @var CustomerMetadataInterface
36
55
*/
@@ -46,23 +65,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
46
65
*/
47
66
private $ storeManager ;
48
67
68
+ /**
69
+ * @var ScopeConfigInterface
70
+ */
71
+ private $ scopeConfig ;
72
+
49
73
/**
50
74
* Document constructor.
51
75
* @param AttributeValueFactory $attributeValueFactory
52
76
* @param GroupRepositoryInterface $groupRepository
53
77
* @param CustomerMetadataInterface $customerMetadata
54
78
* @param StoreManagerInterface $storeManager
79
+ * @param ScopeConfigInterface $scopeConfig
55
80
*/
56
81
public function __construct (
57
82
AttributeValueFactory $ attributeValueFactory ,
58
83
GroupRepositoryInterface $ groupRepository ,
59
84
CustomerMetadataInterface $ customerMetadata ,
60
- StoreManagerInterface $ storeManager
85
+ StoreManagerInterface $ storeManager ,
86
+ ScopeConfigInterface $ scopeConfig = null
61
87
) {
62
88
parent ::__construct ($ attributeValueFactory );
63
89
$ this ->customerMetadata = $ customerMetadata ;
64
90
$ this ->groupRepository = $ groupRepository ;
65
91
$ this ->storeManager = $ storeManager ;
92
+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->create (ScopeConfigInterface::class);
66
93
}
67
94
68
95
/**
@@ -80,6 +107,12 @@ public function getCustomAttribute($attributeCode)
80
107
case self ::$ websiteAttributeCode :
81
108
$ this ->setWebsiteValue ();
82
109
break ;
110
+ case self ::$ confirmationAttributeCode :
111
+ $ this ->setConfirmationValue ();
112
+ break ;
113
+ case self ::$ accountLockAttributeCode :
114
+ $ this ->setAccountLockValue ();
115
+ break ;
83
116
}
84
117
return parent ::getCustomAttribute ($ attributeCode );
85
118
}
@@ -133,5 +166,49 @@ private function setWebsiteValue()
133
166
$ value = $ this ->getData (self ::$ websiteAttributeCode );
134
167
$ list = $ this ->storeManager ->getWebsites ();
135
168
$ this ->setCustomAttribute (self ::$ websiteAttributeCode , $ list [$ value ]->getName ());
169
+ $ this ->setCustomAttribute (self ::$ websiteIdAttributeCode , $ value );
170
+ }
171
+
172
+ /**
173
+ * Update confirmation value
174
+ * Method set confirmation text value to match what is shown in grid
175
+ * @return void
176
+ */
177
+ private function setConfirmationValue ()
178
+ {
179
+ $ value = $ this ->getData (self ::$ confirmationAttributeCode );
180
+ $ websiteId = $ this ->getData (self ::$ websiteIdAttributeCode ) ?: $ this ->getData (self ::$ websiteAttributeCode );
181
+ $ isConfirmRequired = (bool )$ this ->scopeConfig ->getValue (
182
+ AccountManagement::XML_PATH_IS_CONFIRM ,
183
+ ScopeInterface::SCOPE_WEBSITES ,
184
+ $ websiteId
185
+ );
186
+
187
+ $ valueText = __ ('Confirmation Not Required ' );
188
+ if ($ isConfirmRequired ) {
189
+ $ valueText = $ value === null ? __ ('Confirmed ' ) : __ ('Confirmation Required ' );
190
+ }
191
+
192
+ $ this ->setCustomAttribute (self ::$ confirmationAttributeCode , $ valueText );
193
+ }
194
+
195
+ /**
196
+ * Update lock expires value
197
+ * Method set account lock text value to match what is shown in grid
198
+ * @return void
199
+ */
200
+ private function setAccountLockValue ()
201
+ {
202
+ $ value = $ this ->getDataByPath (self ::$ accountLockAttributeCode );
203
+
204
+ $ valueText = __ ('Unlocked ' );
205
+ if ($ value !== null ) {
206
+ $ lockExpires = new \DateTime ($ value );
207
+ if ($ lockExpires > new \DateTime ()) {
208
+ $ valueText = __ ('Locked ' );
209
+ }
210
+ }
211
+
212
+ $ this ->setCustomAttribute (self ::$ accountLockAttributeCode , $ valueText );
136
213
}
137
214
}
0 commit comments