1010use Magento \Framework \EntityManager \MetadataPool ;
1111
1212/**
13- * Class FlatTableBuilder
13+ * Class for building flat index
14+ *
1415 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1516 */
1617class FlatTableBuilder
@@ -346,12 +347,21 @@ protected function _updateTemporaryTableByStoreValues(
346347 }
347348
348349 //Update not simple attributes (eg. dropdown)
349- if (isset ($ flatColumns [$ attributeCode . $ valueFieldSuffix ])) {
350- $ select = $ this ->_connection ->select ()->joinInner (
351- ['t ' => $ this ->_productIndexerHelper ->getTable ('eav_attribute_option_value ' )],
352- 't.option_id = et. ' . $ attributeCode . ' AND t.store_id= ' . $ storeId ,
353- [$ attributeCode . $ valueFieldSuffix => 't.value ' ]
354- );
350+ $ columnName = $ attributeCode . $ valueFieldSuffix ;
351+ if (isset ($ flatColumns [$ columnName ])) {
352+ $ columnValue = $ this ->_connection ->getIfNullSql ('ts.value ' , 't0.value ' );
353+ $ select = $ this ->_connection ->select ();
354+ $ select ->joinLeft (
355+ ['t0 ' => $ this ->_productIndexerHelper ->getTable ('eav_attribute_option_value ' )],
356+ 't0.option_id = et. ' . $ attributeCode . ' AND t0.store_id = 0 ' ,
357+ []
358+ )->joinLeft (
359+ ['ts ' => $ this ->_productIndexerHelper ->getTable ('eav_attribute_option_value ' )],
360+ 'ts.option_id = et. ' . $ attributeCode . ' AND ts.store_id = ' . $ storeId ,
361+ []
362+ )->columns (
363+ [$ columnName => $ columnValue ]
364+ )->where ($ columnValue . ' IS NOT NULL ' );
355365 if (!empty ($ changedIds )) {
356366 $ select ->where ($ this ->_connection ->quoteInto ('et.entity_id IN (?) ' , $ changedIds ));
357367 }
@@ -374,6 +384,8 @@ protected function _getTemporaryTableName($tableName)
374384 }
375385
376386 /**
387+ * Get metadata pool
388+ *
377389 * @return \Magento\Framework\EntityManager\MetadataPool
378390 */
379391 private function getMetadataPool ()
0 commit comments