@@ -168,6 +168,7 @@ public function getStores($storeId = null)
168
168
protected function _getCategoryAttribute ($ attributeCode , $ categoryIds , $ storeId )
169
169
{
170
170
$ linkField = $ this ->metadataPool ->getMetadata (CategoryInterface::class)->getLinkField ();
171
+ $ identifierFiled = $ this ->metadataPool ->getMetadata (CategoryInterface::class)->getIdentifierField ();
171
172
172
173
$ connection = $ this ->getConnection ();
173
174
if (!isset ($ this ->_categoryAttributes [$ attributeCode ])) {
@@ -200,27 +201,28 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
200
201
);
201
202
} elseif ($ this ->_categoryAttributes [$ attributeCode ]['is_global ' ] || $ storeId == 0 ) {
202
203
$ select ->from (
203
- $ attributeTable ,
204
- [$ linkField , ' value ' ]
204
+ [ ' t1 ' => $ this -> getTable ( ' catalog_category_entity ' )] ,
205
+ [$ identifierFiled ]
205
206
)->joinLeft (
206
- ['e ' => $ this -> getTable ( ' catalog_category_entity ' ) ],
207
- "e . {$ linkField } = t1 . {$ linkField }" ,
208
- []
207
+ ['e ' => $ attributeTable ],
208
+ "t1 . {$ linkField } = e . {$ linkField }" ,
209
+ [' value ' ]
209
210
)->where (
210
- 'attribute_id = :attribute_id '
211
+ "t1. {$ identifierFiled } IN(?) " ,
212
+ $ categoryIds
211
213
)->where (
212
- 'store_id = ? ' ,
213
- 0
214
+ 'e.attribute_id = :attribute_id '
214
215
)->where (
215
- 'e.entity_id IN(?) ' ,
216
- $ categoryIds
216
+ 'e.store_id = ? ' ,
217
+ 0
217
218
);
219
+
218
220
$ bind ['attribute_id ' ] = $ this ->_categoryAttributes [$ attributeCode ]['attribute_id ' ];
219
221
} else {
220
222
$ valueExpr = $ connection ->getCheckSql ('t2.value_id > 0 ' , 't2.value ' , 't1.value ' );
221
223
$ select ->from (
222
224
['t1 ' => $ attributeTable ],
223
- [$ linkField , 'value ' => $ valueExpr ]
225
+ [$ identifierFiled => ' e. ' . $ identifierFiled , 'value ' => $ valueExpr ]
224
226
)->joinLeft (
225
227
['t2 ' => $ attributeTable ],
226
228
"t1. {$ linkField } = t2. {$ linkField } AND t1.attribute_id = t2.attribute_id AND t2.store_id = :store_id " ,
@@ -237,7 +239,7 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
237
239
)->where (
238
240
"e.entity_id IN(?) " ,
239
241
$ categoryIds
240
- );
242
+ )-> group ( ' e.entity_id ' ) ;
241
243
242
244
$ bind ['attribute_id ' ] = $ this ->_categoryAttributes [$ attributeCode ]['attribute_id ' ];
243
245
$ bind ['store_id ' ] = $ storeId ;
@@ -247,7 +249,7 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
247
249
248
250
$ attributes = [];
249
251
foreach ($ rowSet as $ row ) {
250
- $ attributes [$ row [$ linkField ]] = $ row ['value ' ];
252
+ $ attributes [$ row [$ identifierFiled ]] = $ row ['value ' ];
251
253
}
252
254
unset($ rowSet );
253
255
foreach ($ categoryIds as $ categoryId ) {
0 commit comments