From ed946c0724936316dcb9152efbf6aa74bd614a50 Mon Sep 17 00:00:00 2001 From: joost-florijn-kega Date: Tue, 1 Nov 2016 14:45:44 +0100 Subject: [PATCH 1/2] Replace boolean cast to be able to disable frame, aspect ratio, transparency or constrain only in view.xml If you set frame to false in view.xml the code would cast it to true because (bool)'false' is equal to true. By using the filter_var function the cast to boolean is done correctly. --- app/code/Magento/Catalog/Model/Product/Image.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index 7d8b464db3b34..8067d6270b64a 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -278,7 +278,7 @@ public function getQuality() */ public function setKeepAspectRatio($keep) { - $this->_keepAspectRatio = (bool)$keep; + $this->_keepAspectRatio = filter_var($keep, FILTER_VALIDATE_BOOLEAN); return $this; } @@ -288,7 +288,7 @@ public function setKeepAspectRatio($keep) */ public function setKeepFrame($keep) { - $this->_keepFrame = (bool)$keep; + $this->_keepFrame = filter_var($keep, FILTER_VALIDATE_BOOLEAN); return $this; } @@ -298,7 +298,7 @@ public function setKeepFrame($keep) */ public function setKeepTransparency($keep) { - $this->_keepTransparency = (bool)$keep; + $this->_keepTransparency = filter_var($keep, FILTER_VALIDATE_BOOLEAN); return $this; } @@ -308,7 +308,7 @@ public function setKeepTransparency($keep) */ public function setConstrainOnly($flag) { - $this->_constrainOnly = (bool)$flag; + $this->_constrainOnly = filter_var($flag, FILTER_VALIDATE_BOOLEAN); return $this; } From 1bbcff4eb26e63611b2372ff74084cb2afb62a8f Mon Sep 17 00:00:00 2001 From: joost-florijn-kega Date: Wed, 2 Nov 2016 08:54:55 +0100 Subject: [PATCH 2/2] Replace filter_var to make the intention of the code clearer --- app/code/Magento/Catalog/Model/Product/Image.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index 8067d6270b64a..b32abc1310498 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -278,7 +278,7 @@ public function getQuality() */ public function setKeepAspectRatio($keep) { - $this->_keepAspectRatio = filter_var($keep, FILTER_VALIDATE_BOOLEAN); + $this->_keepAspectRatio = $keep && $keep !== 'false'; return $this; } @@ -288,7 +288,7 @@ public function setKeepAspectRatio($keep) */ public function setKeepFrame($keep) { - $this->_keepFrame = filter_var($keep, FILTER_VALIDATE_BOOLEAN); + $this->_keepFrame = $keep && $keep !== 'false'; return $this; } @@ -298,7 +298,7 @@ public function setKeepFrame($keep) */ public function setKeepTransparency($keep) { - $this->_keepTransparency = filter_var($keep, FILTER_VALIDATE_BOOLEAN); + $this->_keepTransparency = $keep && $keep !== 'false'; return $this; } @@ -308,7 +308,7 @@ public function setKeepTransparency($keep) */ public function setConstrainOnly($flag) { - $this->_constrainOnly = filter_var($flag, FILTER_VALIDATE_BOOLEAN); + $this->_constrainOnly = $flag && $flag !== 'false'; return $this; }