diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php
index a2be7db7e62be..47839941c5837 100644
--- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php
+++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php
@@ -33,6 +33,7 @@
class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface
{
const DEFAULT_MESSAGE_KEY = 'message';
+ private const RESERVED_ATTRIBUTE_CODES = ['product_type', 'type_id'];
/**
* @var JsonFactory
@@ -145,11 +146,16 @@ public function execute()
);
}
- if ($attribute->getId() && !$attributeId || $attributeCode === 'product_type' || $attributeCode === 'type_id') {
+ if (in_array($attributeCode, self::RESERVED_ATTRIBUTE_CODES, true)) {
+ $message = __('Code (%1) is a reserved key and cannot be used as attribute code.', $attributeCode);
+ $this->setMessageToResponse($response, [$message]);
+ $response->setError(true);
+ }
+
+ if ($attribute->getId() && !$attributeId) {
$message = strlen($this->getRequest()->getParam('attribute_code'))
? __('An attribute with this code already exists.')
: __('An attribute with the same code (%1) already exists.', $attributeCode);
-
$this->setMessageToResponse($response, [$message]);
$response->setError(true);
diff --git a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml
index ffee02080503e..51658dca78c6a 100644
--- a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml
+++ b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml
@@ -385,6 +385,20 @@
Attribute Store label <span>
text
+
+ Type id
+ type_id
+ text
+ No
+ No
+
+
+ Product type
+ product_type
+ text
+ No
+ No
+
attribute
diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml
new file mode 100644
index 0000000000000..591454ad4421c
--- /dev/null
+++ b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Catalog/i18n/en_US.csv b/app/code/Magento/Catalog/i18n/en_US.csv
index 555871ef32c26..7b9d4baacffe5 100644
--- a/app/code/Magento/Catalog/i18n/en_US.csv
+++ b/app/code/Magento/Catalog/i18n/en_US.csv
@@ -209,6 +209,7 @@ Catalog,Catalog
"You saved the product attribute.","You saved the product attribute."
"An attribute with this code already exists.","An attribute with this code already exists."
"An attribute with the same code (%1) already exists.","An attribute with the same code (%1) already exists."
+"Code (%1) is a reserved key and cannot be used as attribute code.","Code (%1) is a reserved key and cannot be used as attribute code."
"The value of Admin must be unique.","The value of Admin must be unique."
"The value of Admin scope can't be empty.","The value of Admin scope can't be empty."
"You duplicated the product.","You duplicated the product."