diff --git a/app/code/Magento/CatalogSearch/Block/Advanced/Form.php b/app/code/Magento/CatalogSearch/Block/Advanced/Form.php index f8c159f5d6d73..19c4891d6cee3 100644 --- a/app/code/Magento/CatalogSearch/Block/Advanced/Form.php +++ b/app/code/Magento/CatalogSearch/Block/Advanced/Form.php @@ -26,15 +26,11 @@ class Form extends Template { /** - * Currency factory - * * @var CurrencyFactory */ protected $_currencyFactory; /** - * Catalog search advanced - * * @var Advanced */ protected $_catalogSearchAdvanced; @@ -125,15 +121,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..383a0093f8412 100644 --- a/app/code/Magento/CatalogSearch/Model/Advanced.php +++ b/app/code/Magento/CatalogSearch/Model/Advanced.php @@ -51,65 +51,47 @@ class Advanced extends \Magento\Framework\Model\AbstractModel { /** - * User friendly search criteria list - * * @var array */ protected $_searchCriterias = []; /** - * Product collection - * * @var ProductCollection */ protected $_productCollection; /** - * Initialize dependencies - * * @deprecated 101.0.2 * @var Config */ protected $_catalogConfig; /** - * Catalog product visibility - * * @var Visibility */ protected $_catalogProductVisibility; /** - * Attribute collection factory - * * @var AttributeCollectionFactory */ protected $_attributeCollectionFactory; /** - * Store manager - * * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; /** - * Product factory - * * @var ProductFactory */ protected $_productFactory; /** - * Currency factory - * * @var CurrencyFactory */ protected $_currencyFactory; /** - * Advanced Collection Factory - * * @deprecated * @see $collectionProvider * @var ProductCollectionFactory @@ -197,12 +179,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, + ] + ] ] ]; }