@@ -56,39 +56,36 @@ public function __construct(
56
56
* @return \Magento\Catalog\Model\Indexer\Product\Flat
57
57
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
58
58
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
59
+ * @SuppressWarnings(PHPMD.NPathComplexity)
59
60
*/
60
61
public function write ($ storeId , $ productId , $ valueFieldSuffix = '' )
61
62
{
62
63
$ flatTable = $ this ->_productIndexerHelper ->getFlatTableName ($ storeId );
64
+ $ entityTableName = $ this ->_productIndexerHelper ->getTable ('catalog_product_entity ' );
63
65
64
66
$ attributes = $ this ->_productIndexerHelper ->getAttributes ();
65
67
$ eavAttributes = $ this ->_productIndexerHelper ->getTablesStructure ($ attributes );
66
68
$ updateData = [];
67
69
$ describe = $ this ->_connection ->describeTable ($ flatTable );
70
+ $ metadata = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class);
71
+ $ linkField = $ metadata ->getLinkField ();
68
72
69
73
foreach ($ eavAttributes as $ tableName => $ tableColumns ) {
70
74
$ columnsChunks = array_chunk ($ tableColumns , self ::ATTRIBUTES_CHUNK_SIZE , true );
71
75
72
76
foreach ($ columnsChunks as $ columns ) {
73
77
$ select = $ this ->_connection ->select ();
74
- $ selectValue = $ this ->_connection ->select ();
75
- $ keyColumns = [
76
- 'entity_id ' => 'e.entity_id ' ,
77
- 'attribute_id ' => 't.attribute_id ' ,
78
- 'value ' => $ this ->_connection ->getIfNullSql ('`t2`.`value` ' , '`t`.`value` ' ),
79
- ];
80
-
81
- if ($ tableName != $ this ->_productIndexerHelper ->getTable ('catalog_product_entity ' )) {
78
+
79
+ if ($ tableName != $ entityTableName ) {
82
80
$ valueColumns = [];
83
81
$ ids = [];
84
82
$ select ->from (
85
- ['e ' => $ this ->_productIndexerHelper ->getTable ('catalog_product_entity ' )],
86
- $ keyColumns
87
- );
88
-
89
- $ selectValue ->from (
90
- ['e ' => $ this ->_productIndexerHelper ->getTable ('catalog_product_entity ' )],
91
- $ keyColumns
83
+ ['e ' => $ entityTableName ],
84
+ [
85
+ 'entity_id ' => 'e.entity_id ' ,
86
+ 'attribute_id ' => 't.attribute_id ' ,
87
+ 'value ' => $ this ->_connection ->getIfNullSql ('`t2`.`value` ' , '`t`.`value` ' ),
88
+ ]
92
89
);
93
90
94
91
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
@@ -97,8 +94,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
97
94
$ ids [$ attribute ->getId ()] = $ columnName ;
98
95
}
99
96
}
100
- $ linkField = $ this ->getMetadataPool ()->getMetadata (ProductInterface::class)->getLinkField ();
101
- $ select ->joinLeft (
97
+ $ select ->joinInner (
102
98
['t ' => $ tableName ],
103
99
sprintf ('e.%s = t.%s ' , $ linkField , $ linkField ) . $ this ->_connection ->quoteInto (
104
100
' AND t.attribute_id IN (?) ' ,
@@ -116,8 +112,6 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
116
112
[]
117
113
)->where (
118
114
'e.entity_id = ' . $ productId
119
- )->where (
120
- 't.attribute_id IS NOT NULL '
121
115
);
122
116
$ cursor = $ this ->_connection ->query ($ select );
123
117
while ($ row = $ cursor ->fetch (\Zend_Db::FETCH_ASSOC )) {
@@ -157,7 +151,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
157
151
$ columnNames [] = 'attribute_set_id ' ;
158
152
$ columnNames [] = 'type_id ' ;
159
153
$ select ->from (
160
- ['e ' => $ this -> _productIndexerHelper -> getTable ( ' catalog_product_entity ' ) ],
154
+ ['e ' => $ entityTableName ],
161
155
$ columnNames
162
156
)->where (
163
157
'e.entity_id = ' . $ productId
@@ -175,7 +169,9 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
175
169
176
170
if (!empty ($ updateData )) {
177
171
$ updateData += ['entity_id ' => $ productId ];
178
- $ updateData += ['row_id ' => $ productId ];
172
+ if ($ linkField !== $ metadata ->getIdentifierField ()) {
173
+ $ updateData += [$ linkField => $ productId ];
174
+ }
179
175
$ updateFields = [];
180
176
foreach ($ updateData as $ key => $ value ) {
181
177
$ updateFields [$ key ] = $ key ;
0 commit comments