From 8a0432dee967c1634f2e60836f37909b1328e0d1 Mon Sep 17 00:00:00 2001 From: Valerij Ivashchenko Date: Fri, 4 May 2018 22:07:18 +0300 Subject: [PATCH 1/6] small optimisation in if-condition --- .../Adminhtml/Product/Initialization/Helper/AttributeFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php index 237168282afae..4641e4fdd7f95 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php @@ -31,7 +31,7 @@ public function prepareProductAttributes(Product $product, array $productData, a $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; if ($value === '' && $considerUseDefaultsAttribute) { /** @var $product Product */ - if ((bool)$product->getData($attribute) === (bool)$value) { + if ((bool)$product->getData($attribute) === false) { unset($productData[$attribute]); } } From 65e9395f5d17be412e92d6faa763803ad8555d28 Mon Sep 17 00:00:00 2001 From: Valerij Ivashchenko Date: Sun, 6 May 2018 00:10:09 +0300 Subject: [PATCH 2/6] optimize 2 nested if to one --- .../Product/Initialization/Helper/AttributeFilter.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php index 4641e4fdd7f95..0c13dd486e325 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php @@ -29,11 +29,8 @@ public function prepareProductAttributes(Product $product, array $productData, a { foreach ($productData as $attribute => $value) { $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; - if ($value === '' && $considerUseDefaultsAttribute) { - /** @var $product Product */ - if ((bool)$product->getData($attribute) === false) { - unset($productData[$attribute]); - } + if ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute)) { + unset($productData[$attribute]); } } return $productData; From bc0019c5434991166fda4dd688ab943c27f57124 Mon Sep 17 00:00:00 2001 From: Valerij Ivashchenko Date: Sun, 6 May 2018 00:24:21 +0300 Subject: [PATCH 3/6] change attributeShouldNotBeUpdated() visibility to protected --- .../Initialization/Helper/AttributeFilter.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php index 0c13dd486e325..4b503721f9400 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php @@ -28,11 +28,24 @@ class AttributeFilter public function prepareProductAttributes(Product $product, array $productData, array $useDefaults) { foreach ($productData as $attribute => $value) { - $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; - if ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute)) { + if ($this->attributeShouldNotBeUpdated($product, $useDefaults, $attribute, $value)) { unset($productData[$attribute]); } } return $productData; } + + /** + * @param $product + * @param $useDefaults + * @param $attribute + * @param $value + * @return bool + */ + protected function attributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value) + { + $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; + + return ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute)); + } } From 6cb5482f7a38d8b41c651ff7f25f4f6724e639f1 Mon Sep 17 00:00:00 2001 From: Valerij Ivashchenko Date: Sun, 6 May 2018 00:28:25 +0300 Subject: [PATCH 4/6] replace tabs by spaces --- .../Initialization/Helper/AttributeFilter.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php index 4b503721f9400..52752a53e9646 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php @@ -35,17 +35,17 @@ public function prepareProductAttributes(Product $product, array $productData, a return $productData; } - /** - * @param $product - * @param $useDefaults - * @param $attribute - * @param $value - * @return bool - */ + /** + * @param $product + * @param $useDefaults + * @param $attribute + * @param $value + * @return bool + */ protected function attributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value) { - $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; + $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1"; - return ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute)); + return ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute)); } } From 2483f6d5b92f09e87e1ab32542dd46c777e90965 Mon Sep 17 00:00:00 2001 From: Valerij Ivashchenko Date: Sun, 6 May 2018 00:30:34 +0300 Subject: [PATCH 5/6] add blank row before return statement --- .../Adminhtml/Product/Initialization/Helper/AttributeFilter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php index 52752a53e9646..f084a6dfad68a 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php @@ -32,6 +32,7 @@ public function prepareProductAttributes(Product $product, array $productData, a unset($productData[$attribute]); } } + return $productData; } From 7e93eed7892d939098b6bd1d9b758233fe0f2b8f Mon Sep 17 00:00:00 2001 From: Valerij Ivashchenko Date: Sun, 6 May 2018 17:18:36 +0300 Subject: [PATCH 6/6] rename attributeShouldNotBeUpdated() to isAttributeShouldNotBeUpdated() --- .../Product/Initialization/Helper/AttributeFilter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php index f084a6dfad68a..1ab952a460cd3 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php @@ -28,22 +28,22 @@ class AttributeFilter public function prepareProductAttributes(Product $product, array $productData, array $useDefaults) { foreach ($productData as $attribute => $value) { - if ($this->attributeShouldNotBeUpdated($product, $useDefaults, $attribute, $value)) { + if ($this->isAttributeShouldNotBeUpdated($product, $useDefaults, $attribute, $value)) { unset($productData[$attribute]); } } - + return $productData; } /** - * @param $product + * @param Product $product * @param $useDefaults * @param $attribute * @param $value * @return bool */ - protected function attributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value) + private function isAttributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value) { $considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";