Skip to content

Commit 31656f2

Browse files
committed
Use visibility class for category product indexer, instead of hardcoded values
1 parent b9101b1 commit 31656f2

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

app/code/Magento/Catalog/Model/Config.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Eav\Model\ResourceModel\Entity\Type\CollectionFactory;
1010
use Magento\Framework\Serialize\SerializerInterface;
11+
use Magento\Catalog\Model\Product\Visibility;
1112

1213
/**
1314
* Catalog config model.
@@ -114,6 +115,11 @@ class Config extends \Magento\Eav\Model\Config
114115
*/
115116
protected $_configFactory;
116117

118+
/**
119+
* @var Visibility
120+
*/
121+
protected $_visibility;
122+
117123
/**
118124
* Constructor
119125
*
@@ -147,6 +153,7 @@ public function __construct(
147153
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setCollectionFactory,
148154
\Magento\Store\Model\StoreManagerInterface $storeManager,
149155
\Magento\Eav\Model\Config $eavConfig,
156+
Visibility $visibility,
150157
SerializerInterface $serializer = null,
151158
$attributesForPreload = []
152159
) {
@@ -157,6 +164,7 @@ public function __construct(
157164
$this->_setCollectionFactory = $setCollectionFactory;
158165
$this->_storeManager = $storeManager;
159166
$this->_eavConfig = $eavConfig;
167+
$this->_visibility = $visibility;
160168

161169
parent::__construct(
162170
$cache,
@@ -506,4 +514,9 @@ public function getProductListDefaultSortBy($store = null)
506514
$store
507515
);
508516
}
517+
518+
public function getVisibility()
519+
{
520+
return $this->_visibility;
521+
}
509522
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,7 @@ protected function getNonAnchorCategoriesSelect(Store $store)
348348
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
349349
)->where(
350350
$this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)',
351-
[
352-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG,
353-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH,
354-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
355-
]
351+
$this->config->getVisibility()->getVisibleInSiteIds()
356352
)->columns(
357353
[
358354
'category_id' => 'cc.entity_id',
@@ -593,11 +589,7 @@ protected function createAnchorSelect(Store $store)
593589
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
594590
)->where(
595591
$this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)',
596-
[
597-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG,
598-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH,
599-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
600-
]
592+
$this->config->getVisibility()->getVisibleInSiteIds()
601593
)->where(
602594
$this->connection->getIfNullSql('ccas.value', 'ccad.value') . ' = ?',
603595
1
@@ -841,11 +833,7 @@ protected function getAllProducts(Store $store)
841833
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
842834
)->where(
843835
$this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)',
844-
[
845-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG,
846-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH,
847-
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
848-
]
836+
$this->config->getVisibility()->getVisibleInSiteIds()
849837
)->group(
850838
'cp.entity_id'
851839
)->columns(

0 commit comments

Comments
 (0)