/
CollectionFilter.php
68 lines (62 loc) · 1.84 KB
/
CollectionFilter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Layer\Search;
use Magento\Catalog\Model\Config;
use Magento\Catalog\Model\Layer\CollectionFilterInterface;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Framework\DB\Select;
use Magento\Store\Model\StoreManagerInterface;
class CollectionFilter implements CollectionFilterInterface
{
/**
* @var Config
*/
protected $catalogConfig;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var Visibility
*/
protected $productVisibility;
/**
* @param Config $catalogConfig
* @param StoreManagerInterface $storeManager
* @param Visibility $productVisibility
*/
public function __construct(
Config $catalogConfig,
StoreManagerInterface $storeManager,
Visibility $productVisibility
) {
$this->catalogConfig = $catalogConfig;
$this->storeManager = $storeManager;
$this->productVisibility = $productVisibility;
}
/**
* Filter product collection
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param \Magento\Catalog\Model\Category $category
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function filter(
$collection,
\Magento\Catalog\Model\Category $category
) {
$collection
->addAttributeToSelect($this->catalogConfig->getProductAttributes())
->setStore($this->storeManager->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite()
->setVisibility($this->productVisibility->getVisibleInSearchIds());
}
}