3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Eav \Model \Entity \Attribute ;
7
8
9
+ use Magento \Eav \Api \Data \AttributeGroupExtensionInterface ;
8
10
use Magento \Framework \Api \AttributeValueFactory ;
11
+ use Magento \Framework \Exception \LocalizedException ;
9
12
10
13
/**
14
+ * Entity attribute group model
15
+ *
11
16
* @api
12
17
* @method int getSortOrder()
13
18
* @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value)
@@ -27,6 +32,11 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
27
32
*/
28
33
private $ translitFilter ;
29
34
35
+ /**
36
+ * @var array
37
+ */
38
+ private $ reservedSystemNames ;
39
+
30
40
/**
31
41
* @param \Magento\Framework\Model\Context $context
32
42
* @param \Magento\Framework\Registry $registry
@@ -35,7 +45,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
35
45
* @param \Magento\Framework\Filter\Translit $translitFilter
36
46
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
37
47
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
38
- * @param array $data
48
+ * @param array $reservedSystemNames (optional)
49
+ * @param array $data (optional)
39
50
*/
40
51
public function __construct (
41
52
\Magento \Framework \Model \Context $ context ,
@@ -45,6 +56,7 @@ public function __construct(
45
56
\Magento \Framework \Filter \Translit $ translitFilter ,
46
57
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
47
58
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
59
+ array $ reservedSystemNames = [],
48
60
array $ data = []
49
61
) {
50
62
parent ::__construct (
@@ -54,8 +66,10 @@ public function __construct(
54
66
$ customAttributeFactory ,
55
67
$ resource ,
56
68
$ resourceCollection ,
69
+ $ reservedSystemNames ,
57
70
$ data
58
71
);
72
+ $ this ->reservedSystemNames = $ reservedSystemNames ;
59
73
$ this ->translitFilter = $ translitFilter ;
60
74
}
61
75
@@ -74,6 +88,7 @@ protected function _construct()
74
88
* Checks if current attribute group exists
75
89
*
76
90
* @return bool
91
+ * @throws LocalizedException
77
92
* @codeCoverageIgnore
78
93
*/
79
94
public function itemExists ()
@@ -85,6 +100,7 @@ public function itemExists()
85
100
* Delete groups
86
101
*
87
102
* @return $this
103
+ * @throws LocalizedException
88
104
* @codeCoverageIgnore
89
105
*/
90
106
public function deleteGroups ()
@@ -110,9 +126,10 @@ public function beforeSave()
110
126
),
111
127
'- '
112
128
);
113
- if (empty ($ attributeGroupCode )) {
114
- // in the following code md5 is not used for security purposes
115
- $ attributeGroupCode = md5 ($ groupName );
129
+ $ isReservedSystemName = in_array (strtolower ($ attributeGroupCode ), $ this ->reservedSystemNames );
130
+ if (empty ($ attributeGroupCode ) || $ isReservedSystemName ) {
131
+ // in the following code sha1 is not used for security purposes
132
+ $ attributeGroupCode = sha1 (strtolower ($ groupName ));
116
133
}
117
134
$ this ->setAttributeGroupCode ($ attributeGroupCode );
118
135
}
@@ -121,7 +138,8 @@ public function beforeSave()
121
138
}
122
139
123
140
/**
124
- * {@inheritdoc}
141
+ * @inheritdoc
142
+ *
125
143
* @codeCoverageIgnoreStart
126
144
*/
127
145
public function getAttributeGroupId ()
@@ -130,64 +148,63 @@ public function getAttributeGroupId()
130
148
}
131
149
132
150
/**
133
- * { @inheritdoc}
151
+ * @inheritdoc
134
152
*/
135
153
public function getAttributeGroupName ()
136
154
{
137
155
return $ this ->getData (self ::GROUP_NAME );
138
156
}
139
157
140
158
/**
141
- * { @inheritdoc}
159
+ * @inheritdoc
142
160
*/
143
161
public function getAttributeSetId ()
144
162
{
145
163
return $ this ->getData (self ::ATTRIBUTE_SET_ID );
146
164
}
147
165
148
166
/**
149
- * { @inheritdoc}
167
+ * @inheritdoc
150
168
*/
151
169
public function setAttributeGroupId ($ attributeGroupId )
152
170
{
153
171
return $ this ->setData (self ::GROUP_ID , $ attributeGroupId );
154
172
}
155
173
156
174
/**
157
- * { @inheritdoc}
175
+ * @inheritdoc
158
176
*/
159
177
public function setAttributeGroupName ($ attributeGroupName )
160
178
{
161
179
return $ this ->setData (self ::GROUP_NAME , $ attributeGroupName );
162
180
}
163
181
164
182
/**
165
- * { @inheritdoc}
183
+ * @inheritdoc
166
184
*/
167
185
public function setAttributeSetId ($ attributeSetId )
168
186
{
169
187
return $ this ->setData (self ::ATTRIBUTE_SET_ID , $ attributeSetId );
170
188
}
171
189
172
190
/**
173
- * { @inheritdoc}
191
+ * @inheritdoc
174
192
*
175
- * @return \Magento\Eav\Api\Data\ AttributeGroupExtensionInterface|null
193
+ * @return AttributeGroupExtensionInterface|null
176
194
*/
177
195
public function getExtensionAttributes ()
178
196
{
179
197
return $ this ->_getExtensionAttributes ();
180
198
}
181
199
182
200
/**
183
- * { @inheritdoc}
201
+ * @inheritdoc
184
202
*
185
- * @param \Magento\Eav\Api\Data\ AttributeGroupExtensionInterface $extensionAttributes
203
+ * @param AttributeGroupExtensionInterface $extensionAttributes
186
204
* @return $this
187
205
*/
188
- public function setExtensionAttributes (
189
- \Magento \Eav \Api \Data \AttributeGroupExtensionInterface $ extensionAttributes
190
- ) {
206
+ public function setExtensionAttributes (AttributeGroupExtensionInterface $ extensionAttributes )
207
+ {
191
208
return $ this ->_setExtensionAttributes ($ extensionAttributes );
192
209
}
193
210
0 commit comments