Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit query length #147

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Block/Catalog/Product/ProductList/Toolbar/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function aroundGetAvailableOrders(Toolbar $subject, Closure $proceed)
return $proceed();
}

if (!$this->context->getResponse()) {
return $proceed();
}

/** @var SortFieldType[] $sortFields */
$sortFields = $this->context->getResponse()->getProperties()->getSortFields();

Expand Down
24 changes: 22 additions & 2 deletions Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Framework\App\Request\Http as MagentoHttpRequest;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\Url;
use Magento\Search\Helper\Data;

class QueryParameterStrategy implements UrlInterface, FilterApplierInterface, CategoryUrlInterface
{
Expand Down Expand Up @@ -89,6 +90,11 @@ class QueryParameterStrategy implements UrlInterface, FilterApplierInterface, Ca
*/
protected $layerUrl;

/**
* @var Data
*/
private Data $searchConfig;

/**
* Magento constructor.
*
Expand All @@ -102,13 +108,15 @@ public function __construct(
StrategyHelper $strategyHelper,
CookieManagerInterface $cookieManager,
TweakwiseConfig $config,
Url $layerUrl
Url $layerUrl,
Data $searchConfig
) {
$this->url = $url;
$this->strategyHelper = $strategyHelper;
$this->cookieManager = $cookieManager;
$this->tweakwiseConfig = $config;
$this->layerUrl = $layerUrl;
$this->searchConfig = $searchConfig;
}

/**
Expand Down Expand Up @@ -504,7 +512,19 @@ protected function getLimit(MagentoHttpRequest $request)
*/
protected function getSearch(MagentoHttpRequest $request)
{
return $request->getQuery(self::PARAM_SEARCH);
$searchLength = 100;
$search = $request->getQuery(self::PARAM_SEARCH);
$maxQueryLength = $this->searchConfig->getMaxQueryLength();

if ($maxQueryLength) {
if ($maxQueryLength < $searchLength) {
$searchLength = $maxQueryLength;
}
}

$search = mb_substr((string) $search, 0, $searchLength);

return $search;
}

/**
Expand Down