6
6
namespace Magento \Catalog \Model \ResourceModel \Product \Indexer \Eav ;
7
7
8
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
+ use Magento \Framework \App \ObjectManager ;
9
10
10
11
/**
11
12
* Catalog Product Eav Attributes abstract indexer resource model
@@ -54,6 +55,7 @@ public function reindexAll()
54
55
$ this ->clearTemporaryIndexTable ();
55
56
$ this ->_prepareIndex ();
56
57
$ this ->_prepareRelationIndex ();
58
+ $ this ->_removeNotVisibleEntityFromIndex ();
57
59
$ this ->syncData ();
58
60
$ this ->commit ();
59
61
} catch (\Exception $ e ) {
@@ -76,6 +78,7 @@ public function reindexEntities($processIds)
76
78
77
79
$ this ->_prepareIndex ($ processIds );
78
80
$ this ->_prepareRelationIndex ($ processIds );
81
+ $ this ->_removeNotVisibleEntityFromIndex ();
79
82
80
83
return $ this ;
81
84
}
@@ -88,7 +91,6 @@ public function reindexEntities($processIds)
88
91
* @param int $attributeId
89
92
* @param bool $isIndexable
90
93
* @return $this
91
- * @throws \Exception
92
94
*/
93
95
public function reindexAttribute ($ attributeId , $ isIndexable = true )
94
96
{
@@ -99,6 +101,7 @@ public function reindexAttribute($attributeId, $isIndexable = true)
99
101
100
102
$ this ->_prepareIndex (null , $ attributeId );
101
103
$ this ->_prepareRelationIndex ();
104
+ $ this ->_removeNotVisibleEntityFromIndex ();
102
105
103
106
$ this ->_synchronizeAttributeIndexData ($ attributeId );
104
107
}
@@ -115,6 +118,39 @@ public function reindexAttribute($attributeId, $isIndexable = true)
115
118
*/
116
119
abstract protected function _prepareIndex ($ entityIds = null , $ attributeId = null );
117
120
121
+ /**
122
+ * Remove Not Visible products from temporary data index
123
+ *
124
+ * @return $this
125
+ */
126
+ protected function _removeNotVisibleEntityFromIndex ()
127
+ {
128
+ $ connection = $ this ->getConnection ();
129
+ $ idxTable = $ this ->getIdxTable ();
130
+
131
+ $ select = $ connection ->select ()->from ($ idxTable , null );
132
+
133
+ $ select ->joinLeft (
134
+ ['cpe ' => $ this ->getTable ('catalog_product_entity ' )],
135
+ "cpe.entity_id = {$ idxTable }.entity_id " ,
136
+ []
137
+ );
138
+ $ linkField = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class)->getLinkField ();
139
+ $ condition = $ connection ->quoteInto ('=? ' , \Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE );
140
+ $ this ->_addAttributeToSelect (
141
+ $ select ,
142
+ 'visibility ' ,
143
+ "cpe. {$ linkField }" ,
144
+ $ idxTable . '.store_id ' ,
145
+ $ condition
146
+ );
147
+
148
+ $ query = $ select ->deleteFromSelect ($ idxTable );
149
+ $ connection ->query ($ query );
150
+
151
+ return $ this ;
152
+ }
153
+
118
154
/**
119
155
* Prepare data index select for product relations
120
156
*
0 commit comments