6
6
namespace Magento \Customer \Model \Config \Backend \Show ;
7
7
8
8
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
9
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
9
10
10
11
/**
11
12
* Customer Show Customer Model
@@ -24,6 +25,21 @@ class Customer extends \Magento\Framework\App\Config\Value
24
25
*/
25
26
protected $ storeManager ;
26
27
28
+ /**
29
+ * @var string
30
+ */
31
+ private $ telephoneShowDefaultValue = 'req ' ;
32
+
33
+ /**
34
+ * @var array
35
+ */
36
+ private $ valueConfig = [
37
+ '' => ['is_required ' => 0 , 'is_visible ' => 0 ],
38
+ 'opt ' => ['is_required ' => 0 , 'is_visible ' => 1 ],
39
+ '1 ' => ['is_required ' => 0 , 'is_visible ' => 1 ],
40
+ 'req ' => ['is_required ' => 1 , 'is_visible ' => 1 ],
41
+ ];
42
+
27
43
/**
28
44
* @param \Magento\Framework\Model\Context $context
29
45
* @param \Magento\Framework\Registry $registry
@@ -80,20 +96,8 @@ public function afterSave()
80
96
{
81
97
$ result = parent ::afterSave ();
82
98
83
- $ valueConfig = [
84
- '' => ['is_required ' => 0 , 'is_visible ' => 0 ],
85
- 'opt ' => ['is_required ' => 0 , 'is_visible ' => 1 ],
86
- '1 ' => ['is_required ' => 0 , 'is_visible ' => 1 ],
87
- 'req ' => ['is_required ' => 1 , 'is_visible ' => 1 ],
88
- ];
89
-
90
99
$ value = $ this ->getValue ();
91
- if (isset ($ valueConfig [$ value ])) {
92
- $ data = $ valueConfig [$ value ];
93
- } else {
94
- $ data = $ valueConfig ['' ];
95
- }
96
-
100
+ $ data = $ this ->getValueConfig ($ value );
97
101
if ($ this ->getScope () == 'websites ' ) {
98
102
$ website = $ this ->storeManager ->getWebsite ($ this ->getScopeCode ());
99
103
$ dataFieldPrefix = 'scope_ ' ;
@@ -133,8 +137,31 @@ public function afterDelete()
133
137
$ attributeObject ->setData ('scope_is_visible ' , null );
134
138
$ attributeObject ->save ();
135
139
}
140
+ } else if ($ this ->getScope () == ScopeConfigInterface::SCOPE_TYPE_DEFAULT ) {
141
+ $ valueConfig = $ this ->getValueConfig ($ this ->telephoneShowDefaultValue );
142
+ foreach ($ this ->_getAttributeObjects () as $ attributeObject ) {
143
+ $ attributeObject ->setData ('is_required ' , $ valueConfig ['is_required ' ]);
144
+ $ attributeObject ->setData ('is_visible ' , $ valueConfig ['is_visible ' ]);
145
+ $ attributeObject ->save ();
146
+ }
136
147
}
137
148
138
149
return $ result ;
139
150
}
151
+
152
+ /**
153
+ * Get value config
154
+ *
155
+ * @param string|int $value
156
+ * @return array
157
+ */
158
+ private function getValueConfig ($ value ): array
159
+ {
160
+ if (isset ($ this ->valueConfig [$ value ])) {
161
+ $ config = $ this ->valueConfig [$ value ];
162
+ } else {
163
+ $ config = $ this ->valueConfig ['' ];
164
+ }
165
+ return $ config ;
166
+ }
140
167
}
0 commit comments