Skip to content

Commit 5b1523e

Browse files
committed
Merge branch 'MAGETWO-43939' of https://github.corp.magento.com/magento-troll/magento2ce into MAGETWO-48184
2 parents 75ac108 + ca44191 commit 5b1523e

File tree

1 file changed

+15
-13
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel

1 file changed

+15
-13
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Url.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function getStores($storeId = null)
168168
protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
169169
{
170170
$linkField = $this->metadataPool->getMetadata(CategoryInterface::class)->getLinkField();
171+
$identifierFiled = $this->metadataPool->getMetadata(CategoryInterface::class)->getIdentifierField();
171172

172173
$connection = $this->getConnection();
173174
if (!isset($this->_categoryAttributes[$attributeCode])) {
@@ -200,27 +201,28 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
200201
);
201202
} elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) {
202203
$select->from(
203-
$attributeTable,
204-
[$linkField, 'value']
204+
['t1' =>$this->getTable('catalog_category_entity')],
205+
[$identifierFiled]
205206
)->joinLeft(
206-
['e' => $this->getTable('catalog_category_entity')],
207-
"e.{$linkField} = t1.{$linkField}",
208-
[]
207+
['e' => $attributeTable],
208+
"t1.{$linkField} = e.{$linkField}",
209+
['value']
209210
)->where(
210-
'attribute_id = :attribute_id'
211+
"t1.{$identifierFiled} IN(?)",
212+
$categoryIds
211213
)->where(
212-
'store_id = ?',
213-
0
214+
'e.attribute_id = :attribute_id'
214215
)->where(
215-
'e.entity_id IN(?)',
216-
$categoryIds
216+
'e.store_id = ?',
217+
0
217218
);
219+
218220
$bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id'];
219221
} else {
220222
$valueExpr = $connection->getCheckSql('t2.value_id > 0', 't2.value', 't1.value');
221223
$select->from(
222224
['t1' => $attributeTable],
223-
[$linkField, 'value' => $valueExpr]
225+
[$identifierFiled => 'e.'.$identifierFiled, 'value' => $valueExpr]
224226
)->joinLeft(
225227
['t2' => $attributeTable],
226228
"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)
237239
)->where(
238240
"e.entity_id IN(?)",
239241
$categoryIds
240-
);
242+
)->group('e.entity_id');
241243

242244
$bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id'];
243245
$bind['store_id'] = $storeId;
@@ -247,7 +249,7 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
247249

248250
$attributes = [];
249251
foreach ($rowSet as $row) {
250-
$attributes[$row[$linkField]] = $row['value'];
252+
$attributes[$row[$identifierFiled]] = $row['value'];
251253
}
252254
unset($rowSet);
253255
foreach ($categoryIds as $categoryId) {

0 commit comments

Comments
 (0)