Skip to content

Commit 612a650

Browse files
committed
MAGETWO-57934: [GitHub] Can't use "configurable" as group name in attribute sets M2.1 #6123
1 parent 310648c commit 612a650

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,11 @@
245245
<type name="Magento\SalesRule\Model\Rule\Condition\Product">
246246
<plugin name="apply_rule_on_configurable_children" type="Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition\Product" />
247247
</type>
248+
<type name="Magento\Eav\Model\Entity\Attribute\Group">
249+
<arguments>
250+
<argument name="reservedSystemNames" xsi:type="array">
251+
<item name="configurable" xsi:type="string">configurable</item>
252+
</argument>
253+
</arguments>
254+
</type>
248255
</config>

app/code/Magento/Eav/Model/Entity/Attribute/Group.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Eav\Model\Entity\Attribute;
78

9+
use Magento\Eav\Api\Data\AttributeGroupExtensionInterface;
810
use Magento\Framework\Api\AttributeValueFactory;
11+
use Magento\Framework\Exception\LocalizedException;
912

1013
/**
14+
* Entity attribute group model
15+
*
1116
* @api
1217
* @method int getSortOrder()
1318
* @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value)
@@ -27,6 +32,11 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
2732
*/
2833
private $translitFilter;
2934

35+
/**
36+
* @var array
37+
*/
38+
private $reservedSystemNames;
39+
3040
/**
3141
* @param \Magento\Framework\Model\Context $context
3242
* @param \Magento\Framework\Registry $registry
@@ -35,7 +45,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
3545
* @param \Magento\Framework\Filter\Translit $translitFilter
3646
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
3747
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
38-
* @param array $data
48+
* @param array $reservedSystemNames (optional)
49+
* @param array $data (optional)
3950
*/
4051
public function __construct(
4152
\Magento\Framework\Model\Context $context,
@@ -45,6 +56,7 @@ public function __construct(
4556
\Magento\Framework\Filter\Translit $translitFilter,
4657
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
4758
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
59+
array $reservedSystemNames = [],
4860
array $data = []
4961
) {
5062
parent::__construct(
@@ -54,8 +66,10 @@ public function __construct(
5466
$customAttributeFactory,
5567
$resource,
5668
$resourceCollection,
69+
$reservedSystemNames,
5770
$data
5871
);
72+
$this->reservedSystemNames = $reservedSystemNames;
5973
$this->translitFilter = $translitFilter;
6074
}
6175

@@ -74,6 +88,7 @@ protected function _construct()
7488
* Checks if current attribute group exists
7589
*
7690
* @return bool
91+
* @throws LocalizedException
7792
* @codeCoverageIgnore
7893
*/
7994
public function itemExists()
@@ -85,6 +100,7 @@ public function itemExists()
85100
* Delete groups
86101
*
87102
* @return $this
103+
* @throws LocalizedException
88104
* @codeCoverageIgnore
89105
*/
90106
public function deleteGroups()
@@ -110,9 +126,10 @@ public function beforeSave()
110126
),
111127
'-'
112128
);
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));
116133
}
117134
$this->setAttributeGroupCode($attributeGroupCode);
118135
}
@@ -121,7 +138,8 @@ public function beforeSave()
121138
}
122139

123140
/**
124-
* {@inheritdoc}
141+
* @inheritdoc
142+
*
125143
* @codeCoverageIgnoreStart
126144
*/
127145
public function getAttributeGroupId()
@@ -130,64 +148,63 @@ public function getAttributeGroupId()
130148
}
131149

132150
/**
133-
* {@inheritdoc}
151+
* @inheritdoc
134152
*/
135153
public function getAttributeGroupName()
136154
{
137155
return $this->getData(self::GROUP_NAME);
138156
}
139157

140158
/**
141-
* {@inheritdoc}
159+
* @inheritdoc
142160
*/
143161
public function getAttributeSetId()
144162
{
145163
return $this->getData(self::ATTRIBUTE_SET_ID);
146164
}
147165

148166
/**
149-
* {@inheritdoc}
167+
* @inheritdoc
150168
*/
151169
public function setAttributeGroupId($attributeGroupId)
152170
{
153171
return $this->setData(self::GROUP_ID, $attributeGroupId);
154172
}
155173

156174
/**
157-
* {@inheritdoc}
175+
* @inheritdoc
158176
*/
159177
public function setAttributeGroupName($attributeGroupName)
160178
{
161179
return $this->setData(self::GROUP_NAME, $attributeGroupName);
162180
}
163181

164182
/**
165-
* {@inheritdoc}
183+
* @inheritdoc
166184
*/
167185
public function setAttributeSetId($attributeSetId)
168186
{
169187
return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
170188
}
171189

172190
/**
173-
* {@inheritdoc}
191+
* @inheritdoc
174192
*
175-
* @return \Magento\Eav\Api\Data\AttributeGroupExtensionInterface|null
193+
* @return AttributeGroupExtensionInterface|null
176194
*/
177195
public function getExtensionAttributes()
178196
{
179197
return $this->_getExtensionAttributes();
180198
}
181199

182200
/**
183-
* {@inheritdoc}
201+
* @inheritdoc
184202
*
185-
* @param \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
203+
* @param AttributeGroupExtensionInterface $extensionAttributes
186204
* @return $this
187205
*/
188-
public function setExtensionAttributes(
189-
\Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
190-
) {
206+
public function setExtensionAttributes(AttributeGroupExtensionInterface $extensionAttributes)
207+
{
191208
return $this->_setExtensionAttributes($extensionAttributes);
192209
}
193210

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/GroupTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected function setUp()
4040
'resource' => $this->resourceMock,
4141
'translitFilter' => $translitFilter,
4242
'context' => $contextMock,
43+
'reservedSystemNames' => ['configurable'],
4344
];
4445
$objectManager = new ObjectManager($this);
4546
$this->model = $objectManager->getObject(
@@ -67,7 +68,9 @@ public function attributeGroupCodeDataProvider()
6768
{
6869
return [
6970
['General Group', 'general-group'],
70-
['///', md5('///')],
71+
['configurable', sha1('configurable')],
72+
['configurAble', sha1('configurable')],
73+
['///', sha1('///')],
7174
];
7275
}
7376
}

app/code/Magento/Eav/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,3 @@
210210
</arguments>
211211
</type>
212212
</config>
213-

0 commit comments

Comments
 (0)