Skip to content

Commit 8992413

Browse files
authored
ENGCOM-9197: 33589 fix array values in catalogsearch parameters #33682
2 parents f6c7652 + 1a71a80 commit 8992413

File tree

3 files changed

+110
-3
lines changed

3 files changed

+110
-3
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ public function addFilters($values)
210210
$this->addSearchCriteria($attribute, $preparedSearchValue);
211211

212212
if ($attribute->getAttributeCode() == 'price') {
213+
foreach ($value as $key => $element) {
214+
if (is_array($element)) {
215+
$value[$key] = 0;
216+
}
217+
}
218+
213219
$rate = 1;
214220
$store = $this->_storeManager->getStore();
215221
$currency = $store->getCurrentCurrencyCode();
@@ -351,23 +357,31 @@ protected function addSearchCriteria($attribute, $value)
351357
/**
352358
* Add data about search criteria to object state
353359
*
354-
* @todo: Move this code to block
355-
*
356360
* @param EntityAttribute $attribute
357361
* @param mixed $value
362+
*
358363
* @return string|bool
359364
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
360365
* @SuppressWarnings(PHPMD.NPathComplexity)
366+
* @throws LocalizedException
367+
* @todo: Move this code to block
368+
*
361369
*/
362370
protected function getPreparedSearchCriteria($attribute, $value)
363371
{
364372
$from = null;
365373
$to = null;
366374
if (is_array($value)) {
375+
foreach ($value as $key => $element) {
376+
if (is_array($element)) {
377+
$value[$key] = '';
378+
}
379+
}
367380
if (isset($value['from']) && isset($value['to'])) {
368381
if (!empty($value['from']) || !empty($value['to'])) {
369382
$from = '';
370383
$to = '';
384+
371385
if (isset($value['currency'])) {
372386
/** @var $currencyModel Currency */
373387
$currencyModel = $this->_currencyFactory->create()->load($value['currency']);

app/code/Magento/CatalogSearch/view/frontend/templates/result.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/** This changes need to valid applying filters and configuration before search process is started. */
7+
use Magento\CatalogSearch\Block\Result;
8+
9+
/** These changes need to valid applying filters and configuration before search process is started. */
10+
11+
/** @var $block Result*/
812
$productList = $block->getProductListHtml();
913
?>
1014
<?php if ($block->getResultCount()) : ?>

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,95 @@ public function testExecuteWithUnderscore(): void
134134
$this->assertStringContainsString('name_simple_product', $responseBody);
135135
}
136136

137+
/**
138+
* Advanced search with array in price parameters
139+
*
140+
* @magentoAppArea frontend
141+
* @magentoDataFixture Magento/CatalogSearch/_files/product_for_search.php
142+
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
143+
* @dataProvider searchParamsInArrayDataProvider
144+
*
145+
* @param array $searchParams
146+
* @return void
147+
*/
148+
public function testExecuteWithArrayInParam(array $searchParams): void
149+
{
150+
$this->getRequest()->setQuery(
151+
$this->_objectManager->create(
152+
Parameters::class,
153+
[
154+
'values' => $searchParams
155+
]
156+
)
157+
);
158+
$this->dispatch('catalogsearch/advanced/result');
159+
$this->assertEquals(200, $this->getResponse()->getStatusCode());
160+
$responseBody = $this->getResponse()->getBody();
161+
$this->assertStringContainsString(
162+
'We can&#039;t find any items matching these search criteria.',
163+
$responseBody
164+
);
165+
}
166+
167+
/**
168+
* Data provider with array in params values
169+
*
170+
* @return array
171+
*/
172+
public function searchParamsInArrayDataProvider(): array
173+
{
174+
return [
175+
'search_with_from_param_is_array' => [
176+
[
177+
'name' => '',
178+
'sku' => '',
179+
'description' => '',
180+
'short_description' => '',
181+
'price' => [
182+
'from' => [],
183+
'to' => 1,
184+
]
185+
]
186+
],
187+
'search_with_to_param_is_array' => [
188+
[
189+
'name' => '',
190+
'sku' => '',
191+
'description' => '',
192+
'short_description' => '',
193+
'price' => [
194+
'from' => 0,
195+
'to' => [],
196+
]
197+
]
198+
],
199+
'search_with_params_in_array' => [
200+
[
201+
'name' => '',
202+
'sku' => '',
203+
'description' => '',
204+
'short_description' => '',
205+
'price' => [
206+
'from' => ['0' => 1],
207+
'to' => [1],
208+
]
209+
]
210+
],
211+
'search_with_params_in_array_in_array' => [
212+
[
213+
'name' => '',
214+
'sku' => '',
215+
'description' => '',
216+
'short_description' => '',
217+
'price' => [
218+
'from' => ['0' => ['0' => 1]],
219+
'to' => 1,
220+
]
221+
]
222+
]
223+
];
224+
}
225+
137226
/**
138227
* Data provider with strings for quick search.
139228
*

0 commit comments

Comments
 (0)