Skip to content

Commit

Permalink
magento#33586: fix php warning message at search advansed result and …
Browse files Browse the repository at this point in the history
…index pages
  • Loading branch information
korovitskyi committed Jan 19, 2022
1 parent 44a86cb commit 7a15c40
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 11 deletions.
9 changes: 3 additions & 6 deletions app/code/Magento/CatalogSearch/Block/Advanced/Form.php
Expand Up @@ -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;
}

/**
Expand Down
13 changes: 8 additions & 5 deletions app/code/Magento/CatalogSearch/Model/Advanced.php
Expand Up @@ -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;
Expand Down
@@ -0,0 +1,115 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogSearch\Controller\Advanced;

use Magento\TestFramework\TestCase\AbstractController;
use Laminas\Stdlib\Parameters;

/**
* Test cases for catalog advanced index using params.
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*/
class IndexTest extends AbstractController
{
/**
* Advanced index test by params with the array in params.
*
* @magentoAppArea frontend
* @dataProvider fromParamsInArrayDataProvider
*
* @param array $searchParams
* @return void
*/
public function testExecuteWithArrayInParams(array $searchParams): void
{
$this->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,
]
]
]
];
}
}
Expand Up @@ -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,
]
]
]
];
}
Expand Down

0 comments on commit 7a15c40

Please sign in to comment.