Skip to content

Commit

Permalink
ENGCOM-9391: #33586: fix php warning message at search advansed resul…
Browse files Browse the repository at this point in the history
…t and index pages #34995
  • Loading branch information
sidolov committed Feb 3, 2022
2 parents 926b334 + 6dd36b1 commit b1de1da
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 33 deletions.
13 changes: 3 additions & 10 deletions app/code/Magento/CatalogSearch/Block/Advanced/Form.php
Expand Up @@ -26,15 +26,11 @@
class Form extends Template
{
/**
* Currency factory
*
* @var CurrencyFactory
*/
protected $_currencyFactory;

/**
* Catalog search advanced
*
* @var Advanced
*/
protected $_catalogSearchAdvanced;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
31 changes: 8 additions & 23 deletions app/code/Magento/CatalogSearch/Model/Advanced.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
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 b1de1da

Please sign in to comment.