Skip to content

Commit cd2519c

Browse files
committed
Merge branch 'ACP2E-2222' of https://github.com/magento-l3/magento2ce into PR-L3-08112023
2 parents 1f2c06d + 134f30b commit cd2519c

File tree

5 files changed

+235
-37
lines changed

5 files changed

+235
-37
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/AbstractIndexer.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Eav\Model\Config;
10+
use Magento\Framework\EntityManager\MetadataPool;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Indexer\Table\StrategyInterface;
13+
use Magento\Framework\Model\ResourceModel\Db\Context;
914

1015
/**
1116
* Catalog Product Indexer Abstract Resource Model
1217
*
18+
* phpcs:disable Magento2.Classes.AbstractApi
1319
* @api
1420
*
1521
* @author Magento Core Team <core@magentocommerce.com>
@@ -18,8 +24,6 @@
1824
abstract class AbstractIndexer extends \Magento\Indexer\Model\ResourceModel\AbstractResource
1925
{
2026
/**
21-
* Eav config
22-
*
2327
* @var \Magento\Eav\Model\Config
2428
*/
2529
protected $_eavConfig;
@@ -33,18 +37,22 @@ abstract class AbstractIndexer extends \Magento\Indexer\Model\ResourceModel\Abst
3337
/**
3438
* Class constructor
3539
*
36-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
37-
* @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy
38-
* @param \Magento\Eav\Model\Config $eavConfig
39-
* @param string $connectionName
40+
* @param Context $context
41+
* @param StrategyInterface $tableStrategy
42+
* @param Config $eavConfig
43+
* @param string|null $connectionName
44+
* @param MetadataPool|null $metadataPool
4045
*/
4146
public function __construct(
4247
\Magento\Framework\Model\ResourceModel\Db\Context $context,
4348
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy,
4449
\Magento\Eav\Model\Config $eavConfig,
45-
$connectionName = null
50+
$connectionName = null,
51+
?\Magento\Framework\EntityManager\MetadataPool $metadataPool = null
4652
) {
4753
$this->_eavConfig = $eavConfig;
54+
$this->metadataPool = $metadataPool ?: \Magento\Framework\App\ObjectManager::getInstance()
55+
->get(\Magento\Framework\EntityManager\MetadataPool::class);
4856
parent::__construct($context, $tableStrategy, $connectionName);
4957
}
5058

@@ -65,12 +73,13 @@ protected function _getAttribute($attributeCode)
6573
* If $condition is not empty apply limitation for select
6674
*
6775
* @param \Magento\Framework\DB\Select $select
68-
* @param string $attrCode the attribute code
69-
* @param string|\Zend_Db_Expr $entity the entity field or expression for condition
70-
* @param string|\Zend_Db_Expr $store the store field or expression for condition
71-
* @param \Zend_Db_Expr $condition the limitation condition
72-
* @param bool $required if required or has condition used INNER join, else - LEFT
73-
* @return \Zend_Db_Expr the attribute value expression
76+
* @param string $attrCode the attribute code
77+
* @param string|\Zend_Db_Expr $entity the entity field or expression for condition
78+
* @param string|\Zend_Db_Expr $store the store field or expression for condition
79+
* @param \Zend_Db_Expr $condition the limitation condition
80+
* @param bool $required if required or has condition used INNER join, else - LEFT
81+
* @return \Zend_Db_Expr the attribute value expression
82+
* @throws LocalizedException
7483
*/
7584
protected function _addAttributeToSelect($select, $attrCode, $entity, $store, $condition = null, $required = false)
7685
{
@@ -158,6 +167,7 @@ protected function _addWebsiteJoinToSelect($select, $store = true, $joinConditio
158167

159168
/**
160169
* Add join for catalog/product_website table
170+
*
161171
* Joined table has alias pw
162172
*
163173
* @param \Magento\Framework\DB\Select $select the select object
@@ -234,15 +244,13 @@ public function getRelationsByParent($parentIds)
234244
}
235245

236246
/**
247+
* Returns table metadata entity
248+
*
237249
* @return \Magento\Framework\EntityManager\MetadataPool
238250
* @since 101.0.0
239251
*/
240252
protected function getMetadataPool()
241253
{
242-
if (null === $this->metadataPool) {
243-
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
244-
->get(\Magento\Framework\EntityManager\MetadataPool::class);
245-
}
246254
return $this->metadataPool;
247255
}
248256
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\
2929
* @param \Magento\Eav\Model\Config $eavConfig
3030
* @param \Magento\Framework\Event\ManagerInterface $eventManager
3131
* @param string $connectionName
32+
* @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool
3233
*/
3334
public function __construct(
3435
\Magento\Framework\Model\ResourceModel\Db\Context $context,
3536
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy,
3637
\Magento\Eav\Model\Config $eavConfig,
3738
\Magento\Framework\Event\ManagerInterface $eventManager,
38-
$connectionName = null
39+
$connectionName = null,
40+
?\Magento\Framework\EntityManager\MetadataPool $metadataPool = null
3941
) {
4042
$this->_eventManager = $eventManager;
41-
parent::__construct($context, $tableStrategy, $eavConfig, $connectionName);
43+
parent::__construct($context, $tableStrategy, $eavConfig, $connectionName, $metadataPool);
4244
}
4345

4446
/**
@@ -112,8 +114,8 @@ public function reindexAttribute($attributeId, $isIndexable = true)
112114
/**
113115
* Prepare data index for indexable attributes
114116
*
115-
* @param array $entityIds the entity ids limitation
116-
* @param int $attributeId the attribute id limitation
117+
* @param array $entityIds the entity ids limitation
118+
* @param int $attributeId the attribute id limitation
117119
* @return $this
118120
*/
119121
abstract protected function _prepareIndex($entityIds = null, $attributeId = null);

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
99
use Magento\Catalog\Api\Data\ProductInterface;
1010
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Model\ResourceModel\Helper;
12+
use Magento\Eav\Api\AttributeRepositoryInterface;
13+
use Magento\Eav\Model\Config;
14+
use Magento\Framework\Api\SearchCriteriaBuilder;
1115
use Magento\Framework\DB\Select;
1216
use Magento\Framework\DB\Sql\UnionExpression;
17+
use Magento\Framework\EntityManager\MetadataPool;
18+
use Magento\Framework\Event\ManagerInterface;
19+
use Magento\Framework\Indexer\Table\StrategyInterface;
20+
use Magento\Framework\Model\ResourceModel\Db\Context;
1321

1422
/**
1523
* Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
@@ -40,31 +48,34 @@ class Source extends AbstractEav
4048
/**
4149
* Construct
4250
*
43-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
44-
* @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy
45-
* @param \Magento\Eav\Model\Config $eavConfig
46-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
47-
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
51+
* @param Context $context
52+
* @param StrategyInterface $tableStrategy
53+
* @param Config $eavConfig
54+
* @param ManagerInterface $eventManager
55+
* @param Helper $resourceHelper
4856
* @param null|string $connectionName
49-
* @param \Magento\Eav\Api\AttributeRepositoryInterface|null $attributeRepository
50-
* @param \Magento\Framework\Api\SearchCriteriaBuilder|null $criteriaBuilder
57+
* @param AttributeRepositoryInterface|null $attributeRepository
58+
* @param SearchCriteriaBuilder|null $criteriaBuilder
59+
* @param MetadataPool|null $metadataPool
5160
*/
5261
public function __construct(
5362
\Magento\Framework\Model\ResourceModel\Db\Context $context,
5463
\Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy,
5564
\Magento\Eav\Model\Config $eavConfig,
5665
\Magento\Framework\Event\ManagerInterface $eventManager,
5766
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
58-
$connectionName = null,
67+
?string $connectionName = null,
5968
\Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository = null,
60-
\Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder = null
69+
\Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder = null,
70+
?\Magento\Framework\EntityManager\MetadataPool $metadataPool = null
6171
) {
6272
parent::__construct(
6373
$context,
6474
$tableStrategy,
6575
$eavConfig,
6676
$eventManager,
67-
$connectionName
77+
$connectionName,
78+
$metadataPool
6879
);
6980
$this->_resourceHelper = $resourceHelper;
7081
$this->attributeRepository = $attributeRepository
@@ -75,6 +86,19 @@ public function __construct(
7586
->get(\Magento\Framework\Api\SearchCriteriaBuilder::class);
7687
}
7788

89+
/**
90+
* @inheritDoc
91+
*/
92+
public function reindexEntities($processIds)
93+
{
94+
$this->clearTemporaryIndexTable();
95+
96+
$this->_prepareIndex($processIds);
97+
$this->_prepareRelationIndex($processIds);
98+
99+
return $this;
100+
}
101+
78102
/**
79103
* Initialize connection and define main index table
80104
*
@@ -135,6 +159,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
135159
* @param int $attributeId the attribute id limitation
136160
* @return $this
137161
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
162+
* @throws \Exception
138163
*/
139164
protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
140165
{
@@ -149,7 +174,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
149174
$attrIdsFlat = implode(',', array_map('intval', $attrIds));
150175
$ifNullSql = $connection->getIfNullSql('pis.value', 'COALESCE(ds.value, dd.value)');
151176

152-
/**@var $select \Magento\Framework\DB\Select*/
177+
/**@var $select Select */
153178
$select = $connection->select()->distinct(true)->from(
154179
['s' => $this->getTable('store')],
155180
[]
@@ -204,6 +229,17 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
204229
'cpe.entity_id AS source_id',
205230
]
206231
);
232+
$visibilityCondition = $connection->quoteInto(
233+
'>?',
234+
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
235+
);
236+
$this->_addAttributeToSelect(
237+
$select,
238+
'visibility',
239+
"cpe.{$productIdField}",
240+
's.store_id',
241+
$visibilityCondition
242+
);
207243

208244
if ($entityIds !== null) {
209245
$ids = implode(',', array_map('intval', $entityIds));
@@ -239,6 +275,14 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
239275
->where('wd.store_id != 0')
240276
->where("cpe.entity_id IN({$ids})");
241277
$select->where("cpe.entity_id IN({$ids})");
278+
$this->_addAttributeToSelect(
279+
$selectWithoutDefaultStore,
280+
'visibility',
281+
"cpe.{$productIdField}",
282+
'wd.store_id',
283+
$visibilityCondition
284+
);
285+
242286
$selects = new UnionExpression(
243287
[$select, $selectWithoutDefaultStore],
244288
Select::SQL_UNION,
@@ -272,6 +316,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
272316
* @param array $entityIds the entity ids limitation
273317
* @param int $attributeId the attribute id limitation
274318
* @return $this
319+
* @throws \Exception
275320
*/
276321
protected function _prepareMultiselectIndex($entityIds = null, $attributeId = null)
277322
{
@@ -358,6 +403,13 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
358403
]
359404
);
360405

406+
$this->_addAttributeToSelect(
407+
$select,
408+
'visibility',
409+
"cpe.{$productIdField}",
410+
'cs.store_id',
411+
$connection->quoteInto('>?', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE)
412+
);
361413
$this->saveDataFromSelect($select, $options);
362414

363415
return $this;
@@ -431,11 +483,11 @@ public function getIdxTable($table = null)
431483
/**
432484
* Save data from select
433485
*
434-
* @param \Magento\Framework\DB\Select $select
486+
* @param Select $select
435487
* @param array $options
436488
* @return void
437489
*/
438-
private function saveDataFromSelect(\Magento\Framework\DB\Select $select, array $options)
490+
private function saveDataFromSelect(Select $select, array $options)
439491
{
440492
$i = 0;
441493
$data = [];

0 commit comments

Comments
 (0)