@@ -135,6 +135,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
135135 * @param int $attributeId the attribute id limitation
136136 * @return $this
137137 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
138+ * @throws \Exception
138139 */
139140 protected function _prepareSelectIndex ($ entityIds = null , $ attributeId = null )
140141 {
@@ -149,7 +150,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
149150 $ attrIdsFlat = implode (', ' , array_map ('intval ' , $ attrIds ));
150151 $ ifNullSql = $ connection ->getIfNullSql ('pis.value ' , 'COALESCE(ds.value, dd.value) ' );
151152
152- /**@var $select \Magento\Framework\DB\ Select*/
153+ /**@var $select Select */
153154 $ select = $ connection ->select ()->distinct (true )->from (
154155 ['s ' => $ this ->getTable ('store ' )],
155156 []
@@ -204,6 +205,15 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
204205 'cpe.entity_id AS source_id ' ,
205206 ]
206207 );
208+ $ visibilityCondition = $ connection ->quoteInto ('>? ' , \Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE );
209+ $ linkField = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class)->getLinkField ();
210+ $ this ->_addAttributeToSelect (
211+ $ select ,
212+ 'visibility ' ,
213+ "cpe. {$ linkField }" ,
214+ 'pis.store_id ' ,
215+ $ visibilityCondition
216+ );
207217
208218 if ($ entityIds !== null ) {
209219 $ ids = implode (', ' , array_map ('intval ' , $ entityIds ));
@@ -239,6 +249,14 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
239249 ->where ('wd.store_id != 0 ' )
240250 ->where ("cpe.entity_id IN( {$ ids }) " );
241251 $ select ->where ("cpe.entity_id IN( {$ ids }) " );
252+ $ this ->_addAttributeToSelect (
253+ $ selectWithoutDefaultStore ,
254+ 'visibility ' ,
255+ "cpe. {$ linkField }" ,
256+ 'd2s.store_id ' ,
257+ $ visibilityCondition
258+ );
259+
242260 $ selects = new UnionExpression (
243261 [$ select , $ selectWithoutDefaultStore ],
244262 Select::SQL_UNION ,
@@ -272,6 +290,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
272290 * @param array $entityIds the entity ids limitation
273291 * @param int $attributeId the attribute id limitation
274292 * @return $this
293+ * @throws \Exception
275294 */
276295 protected function _prepareMultiselectIndex ($ entityIds = null , $ attributeId = null )
277296 {
@@ -358,6 +377,13 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
358377 ]
359378 );
360379
380+ $ this ->_addAttributeToSelect (
381+ $ select ,
382+ 'visibility ' ,
383+ "cpe. {$ productIdField }" ,
384+ 'cs.store_id ' ,
385+ $ connection ->quoteInto ('>? ' , \Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE )
386+ );
361387 $ this ->saveDataFromSelect ($ select , $ options );
362388
363389 return $ this ;
@@ -431,11 +457,11 @@ public function getIdxTable($table = null)
431457 /**
432458 * Save data from select
433459 *
434- * @param \Magento\Framework\DB\ Select $select
460+ * @param Select $select
435461 * @param array $options
436462 * @return void
437463 */
438- private function saveDataFromSelect (\ Magento \ Framework \ DB \ Select $ select , array $ options )
464+ private function saveDataFromSelect (Select $ select , array $ options )
439465 {
440466 $ i = 0 ;
441467 $ data = [];
0 commit comments