Skip to content

Commit fb56dbc

Browse files
ENGCOM-1446: small optimization in if-condition #15002
2 parents f1572a6 + 7e0e205 commit fb56dbc

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,25 @@ class AttributeFilter
2828
public function prepareProductAttributes(Product $product, array $productData, array $useDefaults)
2929
{
3030
foreach ($productData as $attribute => $value) {
31-
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";
32-
if ($value === '' && $considerUseDefaultsAttribute) {
33-
/** @var $product Product */
34-
if ((bool)$product->getData($attribute) === (bool)$value) {
35-
unset($productData[$attribute]);
36-
}
31+
if ($this->isAttributeShouldNotBeUpdated($product, $useDefaults, $attribute, $value)) {
32+
unset($productData[$attribute]);
3733
}
3834
}
35+
3936
return $productData;
4037
}
38+
39+
/**
40+
* @param Product $product
41+
* @param $useDefaults
42+
* @param $attribute
43+
* @param $value
44+
* @return bool
45+
*/
46+
private function isAttributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value)
47+
{
48+
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";
49+
50+
return ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute));
51+
}
4152
}

0 commit comments

Comments
 (0)