Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Layer.php
Go to the documentation of this file.
1 <?php
7 
8 class Layer
9 {
15  protected $stockHelper;
16 
22  protected $scopeConfig;
23 
28  public function __construct(
29  \Magento\CatalogInventory\Helper\Stock $stockHelper,
31  ) {
32  $this->stockHelper = $stockHelper;
33  $this->scopeConfig = $scopeConfig;
34  }
35 
46  \Magento\Catalog\Model\Layer $subject,
48  ) {
49  if ($this->_isEnabledShowOutOfStock()) {
50  return;
51  }
52  $this->stockHelper->addIsInStockFilterToCollection($collection);
53  }
54 
60  protected function _isEnabledShowOutOfStock()
61  {
62  return $this->scopeConfig->isSetFlag(
63  'cataloginventory/options/show_out_of_stock',
64  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
65  );
66  }
67 }
__construct(\Magento\CatalogInventory\Helper\Stock $stockHelper, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
Definition: Layer.php:28
beforePrepareProductCollection(\Magento\Catalog\Model\Layer $subject, \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection)
Definition: Layer.php:45