@@ -357,11 +357,10 @@ public function getProductAttributes($storeId, array $productIds, array $attribu
357
357
$ selects = [];
358
358
$ ifStoreValue = $ this ->connection ->getCheckSql ('t_store.value_id > 0 ' , 't_store.value ' , 't_default.value ' );
359
359
$ linkField = $ this ->metadata ->getLinkField ();
360
- $ tmpTableName = 'index_fulltext_tmp_ ' . time ();
361
- $ this ->connection ->query ('CREATE TEMPORARY TABLE ' . $ tmpTableName . ' ' .
360
+ $ productLinkFieldsToEntityIdMap = $ this ->connection ->fetchPairs (
362
361
$ this ->connection ->select ()->from (
363
362
['cpe ' => $ this ->getTable ('catalog_product_entity ' )],
364
- $ linkField != ' entity_id ' ? [$ linkField , ' entity_id ' ] : [ 'entity_id ' ]
363
+ [$ linkField , 'entity_id ' ]
365
364
)->where (
366
365
'cpe.entity_id IN (?) ' ,
367
366
$ productIds ,
@@ -370,45 +369,53 @@ public function getProductAttributes($storeId, array $productIds, array $attribu
370
369
);
371
370
foreach ($ attributeTypes as $ backendType => $ attributeIds ) {
372
371
if ($ attributeIds ) {
373
- foreach ($ attributeIds as $ attributeId ) {
374
- $ tableName = $ this ->getTable ('catalog_product_entity_ ' . $ backendType );
375
-
376
- $ select = $ this ->connection ->select ()->from (
377
- ['t ' => $ tmpTableName ],
378
- [
379
- 'entity_id ' => 't.entity_id ' ,
380
- $ linkField => 't. ' . $ linkField ,
381
- 'value ' => $ this ->unifyField ($ ifStoreValue , $ backendType ),
382
- ]
383
- )->joinLeft (
384
- ['t_default ' => $ tableName ],
385
- 't. ' . $ linkField . ' = t_default. ' . $ linkField
386
- . ' AND t_default.attribute_id = ' . (int ) $ attributeId
387
- . ' AND t_default.store_id = 0 ' ,
388
- ['attribute_id ' => 't_default.attribute_id ' ]
389
- )->joinLeft (
390
- ['t_store ' => $ tableName ],
391
- 't. ' . $ linkField . ' = t_store. ' . $ linkField
392
- . ' AND t_store.attribute_id = ' . (int ) $ attributeId
393
- . ' AND t_store.store_id = ' . (int ) $ storeId ,
394
-
395
- []
396
- );
397
- $ selects [] = $ select ;
398
- }
399
-
372
+ $ tableName = $ this ->getTable ('catalog_product_entity_ ' . $ backendType );
373
+
374
+ $ select = $ this ->connection ->select ()->from (
375
+ ['t ' => $ tableName ],
376
+ [
377
+ $ linkField => 't. ' . $ linkField ,
378
+ 'attribute_id ' => 't.attribute_id ' ,
379
+ 'value ' => $ this ->unifyField ($ ifStoreValue , $ backendType ),
380
+ ]
381
+ )->joinLeft (
382
+ ['t_store ' => $ tableName ],
383
+ $ this ->connection ->quoteInto (
384
+ 't. ' . $ linkField . '=t_store. ' . $ linkField .
385
+ ' AND t.attribute_id=t_store.attribute_id ' .
386
+ ' AND t_store.store_id = ? ' ,
387
+ $ storeId
388
+ ),
389
+ []
390
+ )->joinLeft (
391
+ ['t_default ' => $ tableName ],
392
+ $ this ->connection ->quoteInto (
393
+ 't. ' . $ linkField . '=t_default. ' . $ linkField .
394
+ ' AND t.attribute_id=t_default.attribute_id ' .
395
+ ' AND t_default.store_id = ? ' ,
396
+ 0
397
+ ),
398
+ []
399
+ )->where (
400
+ 't.attribute_id IN (?) ' ,
401
+ $ attributeIds
402
+ )->where (
403
+ 't. ' . $ linkField . ' IN (?) ' ,
404
+ array_keys ($ productLinkFieldsToEntityIdMap )
405
+ )->distinct ();
406
+ $ selects [] = $ select ;
400
407
}
401
408
}
402
409
403
410
if ($ selects ) {
404
411
$ select = $ this ->connection ->select ()->union ($ selects , Select::SQL_UNION_ALL );
405
412
$ query = $ this ->connection ->query ($ select );
406
413
while ($ row = $ query ->fetch ()) {
407
- $ entityId = $ row [' entity_id ' ];
414
+ $ entityId = $ productLinkFieldsToEntityIdMap [ $ row [$ linkField ] ];
408
415
$ result [$ entityId ][$ row ['attribute_id ' ]] = $ row ['value ' ];
409
416
}
410
417
}
411
- $ this -> connection -> dropTemporaryTable ( $ tmpTableName );
418
+
412
419
return $ result ;
413
420
}
414
421
0 commit comments