Skip to content

Commit 7a15c40

Browse files
committed
#33586: fix php warning message at search advansed result and index pages
1 parent 44a86cb commit 7a15c40

File tree

4 files changed

+138
-11
lines changed

4 files changed

+138
-11
lines changed

app/code/Magento/CatalogSearch/Block/Advanced/Form.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,12 @@ public function getAttributeValidationClass($attribute)
125125
public function getAttributeValue($attribute, $part = null)
126126
{
127127
$value = $this->getRequest()->getQuery($attribute->getAttributeCode());
128+
128129
if ($part && $value) {
129-
if (isset($value[$part])) {
130-
$value = $value[$part];
131-
} else {
132-
$value = '';
133-
}
130+
$value = $value[$part] ?? '';
134131
}
135132

136-
return $value;
133+
return is_array($value) ? '' : $value;
137134
}
138135

139136
/**

app/code/Magento/CatalogSearch/Model/Advanced.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,15 @@ public function addFilters($values)
197197
if (!isset($values[$attribute->getAttributeCode()])) {
198198
continue;
199199
}
200-
if ($attribute->getFrontendInput() == 'text' || $attribute->getFrontendInput() == 'textarea') {
201-
if (!trim($values[$attribute->getAttributeCode()])) {
202-
continue;
203-
}
204-
}
200+
205201
$value = $values[$attribute->getAttributeCode()];
202+
203+
if (($attribute->getFrontendInput() == 'text' || $attribute->getFrontendInput() == 'textarea')
204+
&& (!is_string($value) || !trim($value))
205+
) {
206+
continue;
207+
}
208+
206209
$preparedSearchValue = $this->getPreparedSearchCriteria($attribute, $value);
207210
if (false === $preparedSearchValue) {
208211
continue;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogSearch\Controller\Advanced;
9+
10+
use Magento\TestFramework\TestCase\AbstractController;
11+
use Laminas\Stdlib\Parameters;
12+
13+
/**
14+
* Test cases for catalog advanced index using params.
15+
*
16+
* @magentoDbIsolation disabled
17+
* @magentoAppIsolation enabled
18+
*/
19+
class IndexTest extends AbstractController
20+
{
21+
/**
22+
* Advanced index test by params with the array in params.
23+
*
24+
* @magentoAppArea frontend
25+
* @dataProvider fromParamsInArrayDataProvider
26+
*
27+
* @param array $searchParams
28+
* @return void
29+
*/
30+
public function testExecuteWithArrayInParams(array $searchParams): void
31+
{
32+
$this->getRequest()->setQuery(
33+
$this->_objectManager->create(
34+
Parameters::class,
35+
[
36+
'values' => $searchParams
37+
]
38+
)
39+
);
40+
$this->dispatch('catalogsearch/advanced/index');
41+
$this->assertEquals(200, $this->getResponse()->getStatusCode());
42+
$this->getResponse()->getBody();
43+
}
44+
45+
/**
46+
* Data provider with array in param values.
47+
*
48+
* @return array
49+
*/
50+
public function fromParamsInArrayDataProvider(): array
51+
{
52+
return [
53+
'from_data_with_from_param_is_array' => [
54+
[
55+
'name' => '',
56+
'sku' => '',
57+
'description' => '',
58+
'short_description' => '',
59+
'price' => [
60+
'from' => [],
61+
'to' => 1,
62+
]
63+
]
64+
],
65+
'from_data_with_to_param_is_array' => [
66+
[
67+
'name' => '',
68+
'sku' => '',
69+
'description' => '',
70+
'short_description' => '',
71+
'price' => [
72+
'from' => 0,
73+
'to' => [],
74+
]
75+
]
76+
],
77+
'from_data_with_params_in_array' => [
78+
[
79+
'name' => '',
80+
'sku' => '',
81+
'description' => '',
82+
'short_description' => '',
83+
'price' => [
84+
'from' => ['0' => 1],
85+
'to' => [1],
86+
]
87+
]
88+
],
89+
'from_data_with_params_in_array_in_array' => [
90+
[
91+
'name' => '',
92+
'sku' => '',
93+
'description' => '',
94+
'short_description' => '',
95+
'price' => [
96+
'from' => ['0' => ['0' => 1]],
97+
'to' => 1,
98+
]
99+
]
100+
],
101+
'from_data_with_name_param_is_array' => [
102+
[
103+
'name' => [],
104+
'sku' => '',
105+
'description' => '',
106+
'short_description' => '',
107+
'price' => [
108+
'from' => 0,
109+
'to' => 20,
110+
]
111+
]
112+
]
113+
];
114+
}
115+
}

dev/tests/integration/testsuite/Magento/CatalogSearch/Controller/Advanced/ResultTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ public function searchParamsInArrayDataProvider(): array
219219
'to' => 1,
220220
]
221221
]
222+
],
223+
'search_with_name_param_is_array' => [
224+
[
225+
'name' => [],
226+
'sku' => '',
227+
'description' => '',
228+
'short_description' => '',
229+
'price' => [
230+
'from' => 0,
231+
'to' => 20,
232+
]
233+
]
222234
]
223235
];
224236
}

0 commit comments

Comments
 (0)