File tree Expand file tree Collapse file tree 4 files changed +64
-4
lines changed Expand file tree Collapse file tree 4 files changed +64
-4
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,10 @@ public function __construct(
51
51
* @param int $limit
52
52
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
53
53
*/
54
- public function prepareCollection (string $ searchKey , int $ pageNum , int $ limit
54
+ public function prepareCollection (
55
+ string $ searchKey ,
56
+ int $ pageNum ,
57
+ int $ limit
55
58
): \Magento \Catalog \Model \ResourceModel \Product \Collection {
56
59
$ productCollection = $ this ->productCollectionFactory ->create ();
57
60
$ productCollection ->addAttributeToSelect (ProductInterface::NAME );
Original file line number Diff line number Diff line change @@ -22,12 +22,15 @@ class AddSearchKeyConditionToCollection implements AddFilterToCollectionInterfac
22
22
*
23
23
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24
24
*/
25
- public function addFilter (Collection $ collection , $ field , $ condition = null ) {
25
+ public function addFilter (Collection $ collection , $ field , $ condition = null ) : void
26
+ {
26
27
if (isset ($ condition ['fulltext ' ]) && !empty ($ condition ['fulltext ' ])) {
27
28
$ collection ->addFieldToFilter (
28
- ProductInterface::NAME , $ condition ['fulltext ' ]
29
+ ProductInterface::NAME ,
30
+ $ condition ['fulltext ' ]
29
31
)->addFieldToFilter (
30
- ProductInterface::SKU , $ condition ['fulltext ' ]
32
+ ProductInterface::SKU ,
33
+ $ condition ['fulltext ' ]
31
34
);
32
35
}
33
36
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ declare (strict_types=1 );
8
+
9
+ namespace Magento \CatalogInventory \Model \Plugin ;
10
+
11
+ use Magento \CatalogInventory \Helper \Stock ;
12
+ use Magento \CatalogInventory \Model \Configuration ;
13
+
14
+ class ProductSearch
15
+ {
16
+ /**
17
+ * @var Configuration
18
+ */
19
+ private $ configuration ;
20
+
21
+ /**
22
+ * @var Stock
23
+ */
24
+ private $ stockHelper ;
25
+
26
+ /**
27
+ * ProductLinks constructor.
28
+ *
29
+ * @param Configuration $configuration
30
+ * @param Stock $stockHelper
31
+ */
32
+ public function __construct (Configuration $ configuration , Stock $ stockHelper )
33
+ {
34
+ $ this ->configuration = $ configuration ;
35
+ $ this ->stockHelper = $ stockHelper ;
36
+ }
37
+
38
+ /**
39
+ * @param \Magento\Catalog\Model\ProductLink\Search $subject
40
+ * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
41
+ * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
42
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
43
+ */
44
+ public function afterPrepareCollection (
45
+ \Magento \Catalog \Model \ProductLink \Search $ subject ,
46
+ \Magento \Catalog \Model \ResourceModel \Product \Collection $ collection
47
+ ): \Magento \Catalog \Model \ResourceModel \Product \Collection {
48
+ $ this ->stockHelper ->addIsInStockFilterToCollection ($ collection );
49
+ return $ collection ;
50
+ }
51
+ }
Original file line number Diff line number Diff line change 39
39
</argument >
40
40
</arguments >
41
41
</virtualType >
42
+ <type name =" Magento\Catalog\Model\ProductLink\Search" >
43
+ <plugin name =" processOutOfStockProducts" type =" Magento\CatalogInventory\Model\Plugin\ProductSearch" />
44
+ </type >
42
45
</config >
You can’t perform that action at this time.
0 commit comments