Skip to content

Commit 86b5442

Browse files
committed
Handle autocomplete limit
1 parent 6f077d1 commit 86b5442

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

app/code/Magento/CatalogSearch/Model/Autocomplete/DataProvider.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010
use Magento\Search\Model\QueryFactory;
1111
use Magento\Search\Model\Autocomplete\DataProviderInterface;
1212
use Magento\Search\Model\Autocomplete\ItemFactory;
13+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
14+
use Magento\Store\Model\ScopeInterface;
1315

1416
class DataProvider implements DataProviderInterface
1517
{
18+
/**
19+
* Autocomplete limit
20+
*/
21+
const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit';
22+
1623
/**
1724
* Query factory
1825
*
@@ -27,16 +34,29 @@ class DataProvider implements DataProviderInterface
2734
*/
2835
protected $itemFactory;
2936

37+
/**
38+
* Limit
39+
*
40+
* @var int
41+
*/
42+
protected $limit;
43+
3044
/**
3145
* @param QueryFactory $queryFactory
3246
* @param ItemFactory $itemFactory
3347
*/
3448
public function __construct(
3549
QueryFactory $queryFactory,
36-
ItemFactory $itemFactory
50+
ItemFactory $itemFactory,
51+
ScopeConfig $scopeConfig
3752
) {
3853
$this->queryFactory = $queryFactory;
3954
$this->itemFactory = $itemFactory;
55+
56+
$this->limit = (int) $scopeConfig->getValue(
57+
self::CONFIG_AUTOCOMPLETE_LIMIT,
58+
ScopeInterface::SCOPE_STORE
59+
);
4060
}
4161

4262
/**
@@ -58,7 +78,7 @@ public function getItems()
5878
$result[] = $resultItem;
5979
}
6080
}
61-
return $result;
81+
return ($this->limit) ? array_splice($result, 0, $this->limit) : $result;
6282
}
6383

6484
/**

0 commit comments

Comments
 (0)