From dafa2baa98d54fad17ff0aff71562afeb7eba7ab Mon Sep 17 00:00:00 2001 From: Raphael Petrini Date: Tue, 8 Sep 2020 16:59:18 +0200 Subject: [PATCH 1/6] implement #1189 --- app/code/core/Mage/Adminhtml/Block/Widget/Grid.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index e9581310e42..e3933315236 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -467,7 +467,11 @@ protected function _addColumnFilterToCollection($column) } else { $cond = $column->getFilter()->getCondition(); if ($field && isset($cond)) { - $this->getCollection()->addFieldToFilter($field , $cond); + if (in_array('NULL', array_values($cond), true)) { + $this->getCollection()->addFieldToFilter($field, array('null' => true)); + } else { + $this->getCollection()->addFieldToFilter($field, $cond); + } } } } From 58c3ae81208838bbfbe148c9c2c5f8af32e36fa1 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 8 Jun 2022 23:25:29 +0100 Subject: [PATCH 2/6] Updated the code from luigifab comments --- app/code/core/Mage/Adminhtml/Block/Widget/Grid.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index e3933315236..c186968184b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -461,14 +461,17 @@ protected function _setFilterValues($data) protected function _addColumnFilterToCollection($column) { if ($this->getCollection()) { - $field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex(); + $field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex(); if ($column->getFilterConditionCallback() && $column->getFilterConditionCallback()[0] instanceof self) { call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column); } else { $cond = $column->getFilter()->getCondition(); if ($field && isset($cond)) { - if (in_array('NULL', array_values($cond), true)) { - $this->getCollection()->addFieldToFilter($field, array('null' => true)); + $filtered = array_map(static function ($value) { + return is_object($value) ? $value->__toString() : $value; + }, array_values($cond)); + if (in_array('\'%NULL%\'', $filtered, true) || in_array('NULL', $filtered, true)) { + $this->getCollection()->addFieldToFilter($field, ['null' => true]); } else { $this->getCollection()->addFieldToFilter($field, $cond); } From 47e461c78c1f688161f8b08f5faa2bfa457ce33e Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Tue, 23 Aug 2022 22:35:52 +0100 Subject: [PATCH 3/6] Fixed baseline --- .github/phpstan-baseline.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/phpstan-baseline.neon b/.github/phpstan-baseline.neon index 753843d3df9..bb2ad9b24fa 100644 --- a/.github/phpstan-baseline.neon +++ b/.github/phpstan-baseline.neon @@ -1007,7 +1007,7 @@ parameters: - message: "#^Call to an undefined method Varien_Data_Collection\\:\\:addFieldToFilter\\(\\)\\.$#" - count: 1 + count: 2 path: ../app/code/core/Mage/Adminhtml/Block/Widget/Grid.php - From c8fcff73c4f37a8be89ba92f51304819a11c7efb Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 30 Aug 2022 17:16:41 +0200 Subject: [PATCH 4/6] Fixed phpstan-baseline.neon --- .github/phpstan-baseline.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/phpstan-baseline.neon b/.github/phpstan-baseline.neon index 430443bc1e3..ee7b981a56d 100644 --- a/.github/phpstan-baseline.neon +++ b/.github/phpstan-baseline.neon @@ -767,7 +767,7 @@ parameters: - message: "#^Call to an undefined method Varien_Data_Collection\\:\\:addFieldToFilter\\(\\)\\.$#" - count: 2 + count: 1 path: ../app/code/core/Mage/Adminhtml/Block/Widget/Grid.php - From 4836ae354a7e812e2226def4632f54ba898262d5 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 30 Aug 2022 23:12:54 +0200 Subject: [PATCH 5/6] Fixed PR --- .github/phpstan-baseline.neon | 2 +- app/code/core/Mage/Adminhtml/Block/Widget/Grid.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/phpstan-baseline.neon b/.github/phpstan-baseline.neon index ee7b981a56d..430443bc1e3 100644 --- a/.github/phpstan-baseline.neon +++ b/.github/phpstan-baseline.neon @@ -767,7 +767,7 @@ parameters: - message: "#^Call to an undefined method Varien_Data_Collection\\:\\:addFieldToFilter\\(\\)\\.$#" - count: 1 + count: 2 path: ../app/code/core/Mage/Adminhtml/Block/Widget/Grid.php - diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index ba1c753f9cb..91fd4dd23aa 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -496,7 +496,14 @@ protected function _addColumnFilterToCollection($column) } else { $cond = $column->getFilter()->getCondition(); if ($field && $cond !== null) { - $this->getCollection()->addFieldToFilter($field , $cond); + $filtered = array_map(static function ($value) { + return is_object($value) ? $value->__toString() : $value; + }, array_values($cond)); + if (in_array('\'%NULL%\'', $filtered, true) || in_array('NULL', $filtered, true)) { + $this->getCollection()->addFieldToFilter($field, ['null' => true]); + } else { + $this->getCollection()->addFieldToFilter($field, $cond); + } } } } From 437b359b18ebf0f5d5d39cf922a47916055d7a11 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 31 Aug 2022 00:19:54 +0100 Subject: [PATCH 6/6] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ccfa5bf451..3f3b7c478eb 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,9 @@ Most important changes will be listed here, all other changes since `19.4.0` can ### Between Magento 1.9.4.5 and OpenMage 19.x -- bug fixes and PHP 7.x and 8.0 compatibility +- bug fixes and PHP 7.x, 8.0 and 8.1 compatibility - added config cache for system.xml [#1916](https://github.com/OpenMage/magento-lts/pull/1916) +- search for "NULL" in backend grids [#1203](https://github.com/OpenMage/magento-lts/pull/1203) ### Between OpenMage 19.x and 20.x