Skip to content

Commit

Permalink
Merge pull request #576 from magento-performance/ACPT-1665
Browse files Browse the repository at this point in the history
ACPT-1665:Fix searchConfig merge in SearchCriteriaBuilder
  • Loading branch information
andimov authored Nov 17, 2023
2 parents 2feb4ea + 1a58d72 commit 2cc0a1f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogGraphQl\DataProvider\Product;

use Magento\Framework\ObjectManager\ResetAfterRequestInterface;

/**
* Builds request specific Product Search Query
*/
class RequestDataBuilder implements ResetAfterRequestInterface
{
private array $data;

public function __construct()
{
$this->_resetState();
}

public function setData($data)
{
$this->data = $data;
}

public function getData(string $key)
{
return $this->data[$key] ?? null;

}

/**
* @inheritDoc
*/
public function _resetState(): void
{
$this->data = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class SearchCriteriaBuilder
*/
private SearchConfig $searchConfig;

private RequestDataBuilder $localData;

/**
* @param Builder $builder
* @param ScopeConfigInterface $scopeConfig
Expand All @@ -87,7 +89,8 @@ public function __construct(
Visibility $visibility,
SortOrderBuilder $sortOrderBuilder = null,
Config $eavConfig = null,
SearchConfig $searchConfig = null
SearchConfig $searchConfig = null,
RequestDataBuilder $localData = null,
) {
$this->scopeConfig = $scopeConfig;
$this->filterBuilder = $filterBuilder;
Expand All @@ -97,6 +100,7 @@ public function __construct(
$this->sortOrderBuilder = $sortOrderBuilder ?? ObjectManager::getInstance()->get(SortOrderBuilder::class);
$this->eavConfig = $eavConfig ?? ObjectManager::getInstance()->get(Config::class);
$this->searchConfig = $searchConfig ?? ObjectManager::getInstance()->get(SearchConfig::class);
$this->localData = $localData ?? ObjectManager::getInstance()->get(RequestDataBuilder::class);
}

/**
Expand Down Expand Up @@ -169,7 +173,7 @@ private function updateMatchTypeRequestConfig(string $requestName, array $partia
}
}
}
$this->searchConfig->merge([$requestName => $data]);
$this->localData->setData([$requestName => $data]);
}

/**
Expand Down
19 changes: 16 additions & 3 deletions lib/internal/Magento/Framework/Search/Request/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Magento\Framework\Search\Request;

use Magento\CatalogGraphQl\DataProvider\Product\RequestDataBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
use Magento\Framework\ObjectManagerInterface;
Expand Down Expand Up @@ -49,6 +50,8 @@ class Builder implements ResetAfterRequestInterface
*/
private $cleaner;

private RequestDataBuilder $localData;

/**
* Request Builder constructor
*
Expand All @@ -57,12 +60,18 @@ class Builder implements ResetAfterRequestInterface
* @param Binder $binder
* @param Cleaner $cleaner
*/
public function __construct(ObjectManagerInterface $objectManager, Config $config, Binder $binder, Cleaner $cleaner)
public function __construct(
ObjectManagerInterface $objectManager,
Config $config,
Binder $binder,
Cleaner $cleaner,
RequestDataBuilder $localData = null)
{
$this->objectManager = $objectManager;
$this->config = $config;
$this->binder = $binder;
$this->cleaner = $cleaner;
$this->localData = $localData ?? $this->objectManager->get(RequestDataBuilder::class);
}

/**
Expand Down Expand Up @@ -151,8 +160,12 @@ public function create()
throw new \InvalidArgumentException("Request name not defined.");
}
$requestName = $this->data['requestName'];
/** @var array $data */
$data = $this->config->get($requestName);
if ($this->localData->getData($requestName)) {
$data = $this->localData->getData($requestName);
} else {
/** @var array $data */
$data = $this->config->get($requestName);
}
if ($data === null) {
throw new NonExistingRequestNameException(new Phrase("Request name '%1' doesn't exist.", [$requestName]));
}
Expand Down

0 comments on commit 2cc0a1f

Please sign in to comment.