From 580ffe52adecf0030d21b3fc7bf046706680324a Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid Date: Wed, 10 Jun 2020 14:03:20 +0200 Subject: [PATCH 01/12] change error to code is reserved key instead of code already exists --- .../Adminhtml/Product/Attribute/Validate.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 dcb7074c0d036..a525a5b7d087c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -128,10 +128,13 @@ public function execute() ); if ($attribute->getId() && !$attributeId || $attributeCode === 'product_type' || $attributeCode === 'type_id') { - $message = strlen($this->getRequest()->getParam('attribute_code')) - ? __('An attribute with this code already exists.') - : __('An attribute with the same code (%1) already exists.', $attributeCode); - + if ($attributeCode === 'product_type' || $attributeCode === 'type_id') { + $message = __('Code (%1) is a reserved key and cannot be used as attribute code.', $attributeCode); + } else { + $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); From 9bc6cc96e8437d7f7de6a0bee70e1ecd825c171c Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid Date: Fri, 28 Aug 2020 00:35:39 +0200 Subject: [PATCH 02/12] add constant array and provide MFTF test --- .../Adminhtml/Product/Attribute/Validate.php | 5 +- .../Test/Mftf/Data/ProductAttributeData.xml | 44 ++++++++++++++++++ ...uctAttributeEntityWithReservedKeysTest.xml | 46 +++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml 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 a525a5b7d087c..378862c375be1 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -23,6 +23,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface { const DEFAULT_MESSAGE_KEY = 'message'; + const RESERVED_CODES = ['product_type', 'type_id']; /** * @var \Magento\Framework\Controller\Result\JsonFactory @@ -127,8 +128,8 @@ public function execute() $attributeCode ); - if ($attribute->getId() && !$attributeId || $attributeCode === 'product_type' || $attributeCode === 'type_id') { - if ($attributeCode === 'product_type' || $attributeCode === 'type_id') { + if ($attribute->getId() && !$attributeId || in_array($attributeCode, static::RESERVED_CODES)) { + if (in_array($attributeCode, static::RESERVED_CODES)) { $message = __('Code (%1) is a reserved key and cannot be used as attribute code.', $attributeCode); } else { $message = strlen($this->getRequest()->getParam('attribute_code')) diff --git a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml index ffee02080503e..d0023b5f44773 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml @@ -385,6 +385,50 @@ Attribute Store label <span> text + + Type id + type_id + text + Global + No + No + No + No + No + No + No + No + No + No + No + No + No + No + No + No + + + Product type + product_type + text + Global + No + No + No + No + No + No + No + No + No + No + No + No + No + No + 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..c0fb817262def --- /dev/null +++ b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml @@ -0,0 +1,46 @@ + + + + + + + + + <description value="Admin should not be able to create product attribute with reserved codes"/> + <severity value="BLOCKER"/> + <group value="Catalog"/> + </annotations> + + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + </before> + <after> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + + <!--Navigate to Stores > Attributes > Product.--> + <amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="goToProductAttributesGrid"/> + + <!--Create new Product Attribute as TextField, with type_id code.--> + <actionGroup ref="CreateProductAttributeActionGroup" stepKey="createAttribute"> + <argument name="attribute" value="ProductTypeIdAttribute"/> + </actionGroup> + <see stepKey="seeErrorMessage" selector="{{AdminMessagesSection.errorMessage}}" userInput="Code (type_id) is a reserved key and cannot be used as attribute code."/> + + <!--Navigate to Stores > Attributes > Product.--> + <amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="backToProductAttributesGrid"/> + + <!--Create new Product Attribute as TextField, with product_type code.--> + <actionGroup ref="CreateProductAttributeActionGroup" stepKey="createAttribute2"> + <argument name="attribute" value="ProductProductTypeAttribute"/> + </actionGroup> + + <see stepKey="seeErrorMessage2" selector="{{AdminMessagesSection.errorMessage}}" userInput="Code (product_type) is a reserved key and cannot be used as attribute code."/> + </test> +</tests> From 74aaccde20d0a9e6fc493129c38905a62f3daa97 Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid <abdarrahman.abouzaid@gmail.com> Date: Fri, 28 Aug 2020 00:40:35 +0200 Subject: [PATCH 03/12] update test file --- .../CreateProductAttributeEntityWithReservedKeysTest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml index c0fb817262def..4e2659b53e8d8 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml @@ -13,8 +13,8 @@ <stories value="Create Product Attributes"/> <title value="Attributess with reserved codes should not be created"/> <description value="Admin should not be able to create product attribute with reserved codes"/> - <severity value="BLOCKER"/> - <group value="Catalog"/> + <severity value="AVERAGE"/> + <group value="catalog"/> </annotations> <before> From 9c38339d795d962b83556b2ecf62eaf92899f7b2 Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid <abdarrahman.abouzaid@gmail.com> Date: Fri, 28 Aug 2020 00:49:10 +0200 Subject: [PATCH 04/12] update product attributes data file for mftf --- .../Test/Mftf/Data/ProductAttributeData.xml | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml index d0023b5f44773..51658dca78c6a 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml @@ -389,45 +389,15 @@ <data key="frontend_label">Type id</data> <data key="attribute_code">type_id</data> <data key="frontend_input">text</data> - <data key="scope">Global</data> <data key="is_required">No</data> <data key="is_required_admin">No</data> - <data key="is_unique">No</data> - <data key="is_searchable">No</data> - <data key="is_visible">No</data> - <data key="is_visible_in_advanced_search">No</data> - <data key="is_visible_on_front">No</data> - <data key="is_filterable">No</data> - <data key="is_filterable_in_search">No</data> - <data key="used_in_product_listing">No</data> - <data key="is_used_for_promo_rules">No</data> - <data key="is_comparable">No</data> - <data key="is_used_in_grid">No</data> - <data key="is_visible_in_grid">No</data> - <data key="is_filterable_in_grid">No</data> - <data key="used_for_sort_by">No</data> </entity> <entity name="ProductProductTypeAttribute" type="ProductAttribute"> <data key="frontend_label">Product type</data> <data key="attribute_code">product_type</data> <data key="frontend_input">text</data> - <data key="scope">Global</data> <data key="is_required">No</data> <data key="is_required_admin">No</data> - <data key="is_unique">No</data> - <data key="is_searchable">No</data> - <data key="is_visible">No</data> - <data key="is_visible_in_advanced_search">No</data> - <data key="is_visible_on_front">No</data> - <data key="is_filterable">No</data> - <data key="is_filterable_in_search">No</data> - <data key="used_in_product_listing">No</data> - <data key="is_used_for_promo_rules">No</data> - <data key="is_comparable">No</data> - <data key="is_used_in_grid">No</data> - <data key="is_visible_in_grid">No</data> - <data key="is_filterable_in_grid">No</data> - <data key="used_for_sort_by">No</data> </entity> <!-- Product attribute from file "export_import_configurable_product.csv" --> <entity name="ProductAttributeWithTwoOptionsForExportImport" extends="productAttributeDropdownTwoOptions" type="ProductAttribute"> From f9374c8f5181de605e90a0aa94de7846a374b03a Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid <abdarrahman.abouzaid@gmail.com> Date: Sat, 29 Aug 2020 21:32:40 +0200 Subject: [PATCH 05/12] seperate reserved key check & use self instead of static --- .../Adminhtml/Product/Attribute/Validate.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 378862c375be1..8f7608c428c83 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -128,14 +128,16 @@ public function execute() $attributeCode ); - if ($attribute->getId() && !$attributeId || in_array($attributeCode, static::RESERVED_CODES)) { - if (in_array($attributeCode, static::RESERVED_CODES)) { - $message = __('Code (%1) is a reserved key and cannot be used as attribute code.', $attributeCode); - } else { - $message = strlen($this->getRequest()->getParam('attribute_code')) - ? __('An attribute with this code already exists.') - : __('An attribute with the same code (%1) already exists.', $attributeCode); - } + if (in_array($attributeCode, self::RESERVED_CODES)) { + $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); From 86f0c6b382af6b8566faa6eb9c616c74a33cf837 Mon Sep 17 00:00:00 2001 From: AbdulRahmanAbouzaid <abdarrahman.abouzaid@gmail.com> Date: Mon, 31 Aug 2020 22:32:58 +0200 Subject: [PATCH 06/12] Update app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php in_array with strict Co-authored-by: Lena Orobei <oorobei@adobe.com> --- .../Catalog/Controller/Adminhtml/Product/Attribute/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8f7608c428c83..17e5df2b2bef3 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -128,7 +128,7 @@ public function execute() $attributeCode ); - if (in_array($attributeCode, self::RESERVED_CODES)) { + if (in_array($attributeCode, self::RESERVED_CODES, true)) { $message = __('Code (%1) is a reserved key and cannot be used as attribute code.', $attributeCode); $this->setMessageToResponse($response, [$message]); $response->setError(true); From e95d5d28c3554ebed76749c015df147469a645bd Mon Sep 17 00:00:00 2001 From: AbdulRahmanAbouzaid <abdarrahman.abouzaid@gmail.com> Date: Mon, 31 Aug 2020 22:36:07 +0200 Subject: [PATCH 07/12] Update app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php Co-authored-by: Lena Orobei <oorobei@adobe.com> --- .../Catalog/Controller/Adminhtml/Product/Attribute/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 17e5df2b2bef3..8808610c7e51b 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -23,7 +23,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface { const DEFAULT_MESSAGE_KEY = 'message'; - const RESERVED_CODES = ['product_type', 'type_id']; + private const RESERVED_ATTRIBUTE_CODES = ['product_type', 'type_id']; /** * @var \Magento\Framework\Controller\Result\JsonFactory From d396c0a235c3b70e17f953236a6547a4daf1ec82 Mon Sep 17 00:00:00 2001 From: AbdulRahmanAbouzaid <abdarrahman.abouzaid@gmail.com> Date: Mon, 31 Aug 2020 23:40:20 +0200 Subject: [PATCH 08/12] Update app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php Co-authored-by: Lena Orobei <oorobei@adobe.com> --- .../Catalog/Controller/Adminhtml/Product/Attribute/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8808610c7e51b..179b6619c52da 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -128,7 +128,7 @@ public function execute() $attributeCode ); - if (in_array($attributeCode, self::RESERVED_CODES, true)) { + 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); From 1d0b91b419b0b21a56569b4ced87a39309cb2b33 Mon Sep 17 00:00:00 2001 From: AbdulRahmanAbouzaid <abdarrahman.abouzaid@gmail.com> Date: Tue, 1 Sep 2020 20:49:32 +0200 Subject: [PATCH 09/12] Update app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php Co-authored-by: Lena Orobei <oorobei@adobe.com> --- .../Catalog/Controller/Adminhtml/Product/Attribute/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 179b6619c52da..8beaebd16465d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -128,7 +128,7 @@ public function execute() $attributeCode ); - if (in_array($attributeCode, self:: RESERVED_ATTRIBUTE_CODES, true)) { + 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); From c9a1afa700380c7994f36cf597164cc6faae6038 Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid <abdarrahman.abouzaid@gmail.com> Date: Thu, 10 Sep 2020 16:17:22 +0200 Subject: [PATCH 10/12] update code style --- .../Catalog/Controller/Adminhtml/Product/Attribute/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8beaebd16465d..a27cb1571cdb0 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php @@ -23,7 +23,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface { const DEFAULT_MESSAGE_KEY = 'message'; - private const RESERVED_ATTRIBUTE_CODES = ['product_type', 'type_id']; + private const RESERVED_ATTRIBUTE_CODES = ['product_type', 'type_id']; /** * @var \Magento\Framework\Controller\Result\JsonFactory From 804a049cd3a1063417ac70fb8ec51450d9251d53 Mon Sep 17 00:00:00 2001 From: abdarrahman abouzaid <abdarrahman.abouzaid@gmail.com> Date: Fri, 18 Sep 2020 23:04:39 +0200 Subject: [PATCH 11/12] add error message to translation file --- app/code/Magento/Catalog/i18n/en_US.csv | 1 + 1 file changed, 1 insertion(+) 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." From 1ea5d753f581f4997cc8da3efcd9ded6c5722345 Mon Sep 17 00:00:00 2001 From: Andrii Kalinich <51681435+engcom-Echo@users.noreply.github.com> Date: Tue, 22 Sep 2020 09:58:57 +0300 Subject: [PATCH 12/12] Update severity, testCaseId --- .../CreateProductAttributeEntityWithReservedKeysTest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml index 4e2659b53e8d8..591454ad4421c 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/CreateProductAttributeEntityTest/CreateProductAttributeEntityWithReservedKeysTest.xml @@ -13,7 +13,8 @@ <stories value="Create Product Attributes"/> <title value="Attributess with reserved codes should not be created"/> <description value="Admin should not be able to create product attribute with reserved codes"/> - <severity value="AVERAGE"/> + <severity value="MINOR"/> + <testCaseId value="MC-37806"/> <group value="catalog"/> </annotations>