diff --git a/app/code/Magento/CatalogSearch/Block/Advanced/Form.php b/app/code/Magento/CatalogSearch/Block/Advanced/Form.php index f8c159f5d6d73..f3332959db0df 100644 --- a/app/code/Magento/CatalogSearch/Block/Advanced/Form.php +++ b/app/code/Magento/CatalogSearch/Block/Advanced/Form.php @@ -125,15 +125,12 @@ public function getAttributeValidationClass($attribute) public function getAttributeValue($attribute, $part = null) { $value = $this->getRequest()->getQuery($attribute->getAttributeCode()); + if ($part && $value) { - if (isset($value[$part])) { - $value = $value[$part]; - } else { - $value = ''; - } + $value = $value[$part] ?? ''; } - return $value; + return is_array($value) ? '' : $value; } /** diff --git a/app/code/Magento/CatalogSearch/Model/Advanced.php b/app/code/Magento/CatalogSearch/Model/Advanced.php index cd6bad381d56a..73fdc5125f7cb 100644 --- a/app/code/Magento/CatalogSearch/Model/Advanced.php +++ b/app/code/Magento/CatalogSearch/Model/Advanced.php @@ -197,12 +197,15 @@ public function addFilters($values) if (!isset($values[$attribute->getAttributeCode()])) { continue; } - if ($attribute->getFrontendInput() == 'text' || $attribute->getFrontendInput() == 'textarea') { - if (!trim($values[$attribute->getAttributeCode()])) { - continue; - } - } + $value = $values[$attribute->getAttributeCode()]; + + if (($attribute->getFrontendInput() == 'text' || $attribute->getFrontendInput() == 'textarea') + && (!is_string($value) || !trim($value)) + ) { + continue; + } + $preparedSearchValue = $this->getPreparedSearchCriteria($attribute, $value); if (false === $preparedSearchValue) { continue; diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/IndexTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/IndexTest.php new file mode 100644 index 0000000000000..a6b13e8466119 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/IndexTest.php @@ -0,0 +1,115 @@ +getRequest()->setQuery( + $this->_objectManager->create( + Parameters::class, + [ + 'values' => $searchParams + ] + ) + ); + $this->dispatch('catalogsearch/advanced/index'); + $this->assertEquals(200, $this->getResponse()->getStatusCode()); + $this->getResponse()->getBody(); + } + + /** + * Data provider with array in param values. + * + * @return array + */ + public function fromParamsInArrayDataProvider(): array + { + return [ + 'from_data_with_from_param_is_array' => [ + [ + 'name' => '', + 'sku' => '', + 'description' => '', + 'short_description' => '', + 'price' => [ + 'from' => [], + 'to' => 1, + ] + ] + ], + 'from_data_with_to_param_is_array' => [ + [ + 'name' => '', + 'sku' => '', + 'description' => '', + 'short_description' => '', + 'price' => [ + 'from' => 0, + 'to' => [], + ] + ] + ], + 'from_data_with_params_in_array' => [ + [ + 'name' => '', + 'sku' => '', + 'description' => '', + 'short_description' => '', + 'price' => [ + 'from' => ['0' => 1], + 'to' => [1], + ] + ] + ], + 'from_data_with_params_in_array_in_array' => [ + [ + 'name' => '', + 'sku' => '', + 'description' => '', + 'short_description' => '', + 'price' => [ + 'from' => ['0' => ['0' => 1]], + 'to' => 1, + ] + ] + ], + 'from_data_with_name_param_is_array' => [ + [ + 'name' => [], + 'sku' => '', + 'description' => '', + 'short_description' => '', + 'price' => [ + 'from' => 0, + 'to' => 20, + ] + ] + ] + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/ResultTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/ResultTest.php index fb1f7102a3d7e..31e62e520222b 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/ResultTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/ResultTest.php @@ -219,6 +219,18 @@ public function searchParamsInArrayDataProvider(): array 'to' => 1, ] ] + ], + 'search_with_name_param_is_array' => [ + [ + 'name' => [], + 'sku' => '', + 'description' => '', + 'short_description' => '', + 'price' => [ + 'from' => 0, + 'to' => 20, + ] + ] ] ]; }