8
8
use Magento \Catalog \Model \Product \Attribute \Source \Status as ProductStatus ;
9
9
use Magento \Catalog \Api \Data \ProductInterface ;
10
10
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 ;
11
15
use Magento \Framework \DB \Select ;
12
16
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 ;
13
21
14
22
/**
15
23
* Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
@@ -40,31 +48,34 @@ class Source extends AbstractEav
40
48
/**
41
49
* Construct
42
50
*
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
48
56
* @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
51
60
*/
52
61
public function __construct (
53
62
\Magento \Framework \Model \ResourceModel \Db \Context $ context ,
54
63
\Magento \Framework \Indexer \Table \StrategyInterface $ tableStrategy ,
55
64
\Magento \Eav \Model \Config $ eavConfig ,
56
65
\Magento \Framework \Event \ManagerInterface $ eventManager ,
57
66
\Magento \Catalog \Model \ResourceModel \Helper $ resourceHelper ,
58
- $ connectionName = null ,
67
+ ? string $ connectionName = null ,
59
68
\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
61
71
) {
62
72
parent ::__construct (
63
73
$ context ,
64
74
$ tableStrategy ,
65
75
$ eavConfig ,
66
76
$ eventManager ,
67
- $ connectionName
77
+ $ connectionName ,
78
+ $ metadataPool
68
79
);
69
80
$ this ->_resourceHelper = $ resourceHelper ;
70
81
$ this ->attributeRepository = $ attributeRepository
@@ -75,6 +86,19 @@ public function __construct(
75
86
->get (\Magento \Framework \Api \SearchCriteriaBuilder::class);
76
87
}
77
88
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
+
78
102
/**
79
103
* Initialize connection and define main index table
80
104
*
@@ -135,6 +159,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
135
159
* @param int $attributeId the attribute id limitation
136
160
* @return $this
137
161
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
162
+ * @throws \Exception
138
163
*/
139
164
protected function _prepareSelectIndex ($ entityIds = null , $ attributeId = null )
140
165
{
@@ -149,7 +174,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
149
174
$ attrIdsFlat = implode (', ' , array_map ('intval ' , $ attrIds ));
150
175
$ ifNullSql = $ connection ->getIfNullSql ('pis.value ' , 'COALESCE(ds.value, dd.value) ' );
151
176
152
- /**@var $select \Magento\Framework\DB\ Select*/
177
+ /**@var $select Select */
153
178
$ select = $ connection ->select ()->distinct (true )->from (
154
179
['s ' => $ this ->getTable ('store ' )],
155
180
[]
@@ -204,6 +229,17 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
204
229
'cpe.entity_id AS source_id ' ,
205
230
]
206
231
);
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
+ );
207
243
208
244
if ($ entityIds !== null ) {
209
245
$ ids = implode (', ' , array_map ('intval ' , $ entityIds ));
@@ -239,6 +275,14 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
239
275
->where ('wd.store_id != 0 ' )
240
276
->where ("cpe.entity_id IN( {$ ids }) " );
241
277
$ 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
+
242
286
$ selects = new UnionExpression (
243
287
[$ select , $ selectWithoutDefaultStore ],
244
288
Select::SQL_UNION ,
@@ -272,6 +316,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
272
316
* @param array $entityIds the entity ids limitation
273
317
* @param int $attributeId the attribute id limitation
274
318
* @return $this
319
+ * @throws \Exception
275
320
*/
276
321
protected function _prepareMultiselectIndex ($ entityIds = null , $ attributeId = null )
277
322
{
@@ -358,6 +403,13 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
358
403
]
359
404
);
360
405
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
+ );
361
413
$ this ->saveDataFromSelect ($ select , $ options );
362
414
363
415
return $ this ;
@@ -431,11 +483,11 @@ public function getIdxTable($table = null)
431
483
/**
432
484
* Save data from select
433
485
*
434
- * @param \Magento\Framework\DB\ Select $select
486
+ * @param Select $select
435
487
* @param array $options
436
488
* @return void
437
489
*/
438
- private function saveDataFromSelect (\ Magento \ Framework \ DB \ Select $ select , array $ options )
490
+ private function saveDataFromSelect (Select $ select , array $ options )
439
491
{
440
492
$ i = 0 ;
441
493
$ data = [];
0 commit comments