33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \CatalogInventory \Model \Plugin ;
78
9+ use Magento \Framework \Search \EngineResolverInterface ;
10+ use Magento \Search \Model \EngineResolver ;
11+
12+ /**
13+ * Catalog inventory plugin for layer.
14+ */
815class Layer
916{
1017 /**
@@ -21,16 +28,24 @@ class Layer
2128 */
2229 protected $ scopeConfig ;
2330
31+ /**
32+ * @var EngineResolverInterface
33+ */
34+ private $ engineResolver ;
35+
2436 /**
2537 * @param \Magento\CatalogInventory\Helper\Stock $stockHelper
2638 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
39+ * @param EngineResolverInterface $engineResolver
2740 */
2841 public function __construct (
2942 \Magento \CatalogInventory \Helper \Stock $ stockHelper ,
30- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
43+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
44+ EngineResolverInterface $ engineResolver
3145 ) {
3246 $ this ->stockHelper = $ stockHelper ;
3347 $ this ->scopeConfig = $ scopeConfig ;
48+ $ this ->engineResolver = $ engineResolver ;
3449 }
3550
3651 /**
@@ -46,12 +61,22 @@ public function beforePrepareProductCollection(
4661 \Magento \Catalog \Model \Layer $ subject ,
4762 \Magento \Catalog \Model \ResourceModel \Collection \AbstractCollection $ collection
4863 ) {
49- if ($ this ->_isEnabledShowOutOfStock ()) {
64+ if (! $ this -> isCurrentEngineMysql () || $ this ->_isEnabledShowOutOfStock ()) {
5065 return ;
5166 }
5267 $ this ->stockHelper ->addIsInStockFilterToCollection ($ collection );
5368 }
5469
70+ /**
71+ * Check if current engine is MYSQL.
72+ *
73+ * @return bool
74+ */
75+ private function isCurrentEngineMysql ()
76+ {
77+ return $ this ->engineResolver ->getCurrentSearchEngine () === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE ;
78+ }
79+
5580 /**
5681 * Get config value for 'display out of stock' option
5782 *
0 commit comments