7
7
8
8
use Magento \Catalog \Model \Indexer \Product \Flat \FlatTableBuilder ;
9
9
use Magento \Catalog \Model \Indexer \Product \Flat \TableBuilder ;
10
+ use Magento \Framework \EntityManager \MetadataPool ;
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
10
12
11
13
/**
12
14
* Class Row reindex action
@@ -22,6 +24,10 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
22
24
* @var Eraser
23
25
*/
24
26
protected $ flatItemEraser ;
27
+ /**
28
+ * @var MetadataPool
29
+ */
30
+ private $ metadataPool ;
25
31
26
32
/**
27
33
* @param \Magento\Framework\App\ResourceConnection $resource
@@ -32,6 +38,7 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
32
38
* @param FlatTableBuilder $flatTableBuilder
33
39
* @param Indexer $flatItemWriter
34
40
* @param Eraser $flatItemEraser
41
+ * @param MetadataPool $metadataPool
35
42
*/
36
43
public function __construct (
37
44
\Magento \Framework \App \ResourceConnection $ resource ,
@@ -41,7 +48,8 @@ public function __construct(
41
48
TableBuilder $ tableBuilder ,
42
49
FlatTableBuilder $ flatTableBuilder ,
43
50
Indexer $ flatItemWriter ,
44
- Eraser $ flatItemEraser
51
+ Eraser $ flatItemEraser ,
52
+ MetadataPool $ metadataPool
45
53
) {
46
54
parent ::__construct (
47
55
$ resource ,
@@ -53,6 +61,7 @@ public function __construct(
53
61
);
54
62
$ this ->flatItemWriter = $ flatItemWriter ;
55
63
$ this ->flatItemEraser = $ flatItemEraser ;
64
+ $ this ->metadataPool = $ metadataPool ;
56
65
}
57
66
58
67
/**
@@ -75,18 +84,45 @@ public function execute($id = null)
75
84
if ($ tableExists ) {
76
85
$ this ->flatItemEraser ->removeDeletedProducts ($ ids , $ store ->getId ());
77
86
}
78
- if (isset ($ ids [0 ])) {
79
- if (!$ tableExists ) {
80
- $ this ->_flatTableBuilder ->build (
81
- $ store ->getId (),
82
- [$ ids [0 ]],
83
- $ this ->_valueFieldSuffix ,
84
- $ this ->_tableDropSuffix ,
85
- false
86
- );
87
+
88
+ /* @var $status \Magento\Eav\Model\Entity\Attribute */
89
+ $ status = $ this ->_productIndexerHelper ->getAttribute ('status ' );
90
+ $ statusTable = $ status ->getBackendTable ();
91
+ $ statusConditions = [
92
+ 'store_id IN(0, ' . (int )$ store ->getId () . ') ' ,
93
+ 'attribute_id = ' . (int )$ status ->getId (),
94
+ 'entity_id = ' . (int )$ id
95
+ ];
96
+ $ select = $ this ->_connection ->select ();
97
+ $ select ->from (
98
+ $ statusTable ,
99
+ ['value ' ]
100
+ )->where (
101
+ implode (' AND ' , $ statusConditions )
102
+ )->order (
103
+ 'store_id DESC '
104
+ );
105
+ $ result = $ this ->_connection ->query ($ select );
106
+ $ status = $ result ->fetch (1 );
107
+
108
+ if ($ status ['value ' ] == \Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_ENABLED ) {
109
+ if (isset ($ ids [0 ])) {
110
+ if (!$ tableExists ) {
111
+ $ this ->_flatTableBuilder ->build (
112
+ $ store ->getId (),
113
+ [$ ids [0 ]],
114
+ $ this ->_valueFieldSuffix ,
115
+ $ this ->_tableDropSuffix ,
116
+ false
117
+ );
118
+ }
119
+ $ this ->flatItemWriter ->write ($ store ->getId (), $ ids [0 ], $ this ->_valueFieldSuffix );
87
120
}
88
- $ this ->flatItemWriter ->write ($ store ->getId (), $ ids [0 ], $ this ->_valueFieldSuffix );
121
+ } else {
122
+ $ this ->flatItemEraser ->deleteProductsFromStore ($ id , $ store ->getId ());
89
123
}
124
+
125
+
90
126
}
91
127
return $ this ;
92
128
}
0 commit comments