10
10
use Magento \Search \Model \QueryFactory ;
11
11
use Magento \Search \Model \Autocomplete \DataProviderInterface ;
12
12
use Magento \Search \Model \Autocomplete \ItemFactory ;
13
+ use Magento \Framework \App \Config \ScopeConfigInterface as ScopeConfig ;
14
+ use Magento \Store \Model \ScopeInterface ;
13
15
14
16
class DataProvider implements DataProviderInterface
15
17
{
18
+ /**
19
+ * Autocomplete limit
20
+ */
21
+ const CONFIG_AUTOCOMPLETE_LIMIT = 'catalog/search/autocomplete_limit ' ;
22
+
16
23
/**
17
24
* Query factory
18
25
*
@@ -27,16 +34,29 @@ class DataProvider implements DataProviderInterface
27
34
*/
28
35
protected $ itemFactory ;
29
36
37
+ /**
38
+ * Limit
39
+ *
40
+ * @var int
41
+ */
42
+ protected $ limit ;
43
+
30
44
/**
31
45
* @param QueryFactory $queryFactory
32
46
* @param ItemFactory $itemFactory
33
47
*/
34
48
public function __construct (
35
49
QueryFactory $ queryFactory ,
36
- ItemFactory $ itemFactory
50
+ ItemFactory $ itemFactory ,
51
+ ScopeConfig $ scopeConfig
37
52
) {
38
53
$ this ->queryFactory = $ queryFactory ;
39
54
$ this ->itemFactory = $ itemFactory ;
55
+
56
+ $ this ->limit = (int ) $ scopeConfig ->getValue (
57
+ self ::CONFIG_AUTOCOMPLETE_LIMIT ,
58
+ ScopeInterface::SCOPE_STORE
59
+ );
40
60
}
41
61
42
62
/**
@@ -58,7 +78,7 @@ public function getItems()
58
78
$ result [] = $ resultItem ;
59
79
}
60
80
}
61
- return $ result ;
81
+ return ( $ this -> limit ) ? array_splice ( $ result , 0 , $ this -> limit ) : $ result ;
62
82
}
63
83
64
84
/**
0 commit comments