Skip to content

Commit 95e6a20

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

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

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

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

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

1312
/**
1413
* Catalog config model.
@@ -115,11 +114,6 @@ class Config extends \Magento\Eav\Model\Config
115114
*/
116115
protected $_configFactory;
117116

118-
/**
119-
* @var Visibility
120-
*/
121-
protected $_visibility;
122-
123117
/**
124118
* Constructor
125119
*
@@ -153,7 +147,6 @@ public function __construct(
153147
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $setCollectionFactory,
154148
\Magento\Store\Model\StoreManagerInterface $storeManager,
155149
\Magento\Eav\Model\Config $eavConfig,
156-
Visibility $visibility,
157150
SerializerInterface $serializer = null,
158151
$attributesForPreload = []
159152
) {
@@ -164,7 +157,6 @@ public function __construct(
164157
$this->_setCollectionFactory = $setCollectionFactory;
165158
$this->_storeManager = $storeManager;
166159
$this->_eavConfig = $eavConfig;
167-
$this->_visibility = $visibility;
168160

169161
parent::__construct(
170162
$cache,
@@ -514,9 +506,4 @@ public function getProductListDefaultSortBy($store = null)
514506
$store
515507
);
516508
}
517-
518-
public function getVisibility()
519-
{
520-
return $this->_visibility;
521-
}
522509
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\EntityManager\MetadataPool;
1616
use Magento\Store\Api\Data\StoreInterface;
1717
use Magento\Store\Model\Store;
18+
use Magento\Catalog\Model\Product\Visibility;
1819

1920
// phpcs:disable Magento2.Classes.AbstractApi
2021
/**
@@ -131,6 +132,11 @@ abstract class AbstractAction
131132
*/
132133
private $currentStore;
133134

135+
/**
136+
* @var Visibility
137+
*/
138+
private $visibility;
139+
134140
/**
135141
* @param ResourceConnection $resource
136142
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -145,7 +151,8 @@ public function __construct(
145151
\Magento\Catalog\Model\Config $config,
146152
QueryGenerator $queryGenerator = null,
147153
MetadataPool $metadataPool = null,
148-
TableMaintainer $tableMaintainer = null
154+
TableMaintainer $tableMaintainer = null,
155+
Visibility $visibility = null
149156
) {
150157
$this->resource = $resource;
151158
$this->connection = $resource->getConnection();
@@ -154,6 +161,7 @@ public function __construct(
154161
$this->queryGenerator = $queryGenerator ?: ObjectManager::getInstance()->get(QueryGenerator::class);
155162
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
156163
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
164+
$this->visibility = $visibility ?: ObjectManager::getInstance()->get(Visibility::class);
157165
}
158166

159167
/**
@@ -348,7 +356,7 @@ protected function getNonAnchorCategoriesSelect(Store $store)
348356
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
349357
)->where(
350358
$this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)',
351-
$this->config->getVisibility()->getVisibleInSiteIds()
359+
$this->visibility->getVisibleInSiteIds()
352360
)->columns(
353361
[
354362
'category_id' => 'cc.entity_id',
@@ -589,7 +597,7 @@ protected function createAnchorSelect(Store $store)
589597
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
590598
)->where(
591599
$this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)',
592-
$this->config->getVisibility()->getVisibleInSiteIds()
600+
$this->visibility->getVisibleInSiteIds()
593601
)->where(
594602
$this->connection->getIfNullSql('ccas.value', 'ccad.value') . ' = ?',
595603
1
@@ -833,7 +841,7 @@ protected function getAllProducts(Store $store)
833841
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
834842
)->where(
835843
$this->connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)',
836-
$this->config->getVisibility()->getVisibleInSiteIds()
844+
$this->visibility->getVisibleInSiteIds()
837845
)->group(
838846
'cp.entity_id'
839847
)->columns(

0 commit comments

Comments
 (0)