Skip to content

Commit 01f1f15

Browse files
committed
Reworked query in getAttributeRawValue so that it returns a store specific value even if there is no default value
1 parent 6e534ad commit 01f1f15

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,19 @@ public function getAttributeRawValue($entityId, $attribute, $store)
560560
$store = (int) $store;
561561
if ($typedAttributes) {
562562
foreach ($typedAttributes as $table => $_attributes) {
563+
$defaultJoinCondition = [
564+
$connection->quoteInto('default_value.attribute_id IN (?)', array_keys($_attributes)),
565+
"default_value.{$this->getLinkField()} = e.{$this->getLinkField()}",
566+
'default_value.store_id = 0',
567+
];
568+
563569
$select = $connection->select()
564-
->from(['default_value' => $table], ['attribute_id'])
565-
->join(
566-
['e' => $this->getTable($this->getEntityTable())],
567-
'e.' . $this->getLinkField() . ' = ' . 'default_value.' . $this->getLinkField(),
568-
''
569-
)->where('default_value.attribute_id IN (?)', array_keys($_attributes))
570-
->where("e.entity_id = :entity_id")
571-
->where('default_value.store_id = ?', 0);
570+
->from(['e' => $this->getTable($this->getEntityTable())], [])
571+
->joinLeft(
572+
['default_value' => $table],
573+
implode(' AND ', $defaultJoinCondition),
574+
[]
575+
)->where("e.entity_id = :entity_id");
572576

573577
$bind = ['entity_id' => $entityId];
574578

@@ -578,6 +582,11 @@ public function getAttributeRawValue($entityId, $attribute, $store)
578582
'default_value.value',
579583
'store_value.value'
580584
);
585+
$attributeIdExpr = $connection->getCheckSql(
586+
'store_value.attribute_id IS NULL',
587+
'default_value.attribute_id',
588+
'store_value.attribute_id'
589+
);
581590
$joinCondition = [
582591
$connection->quoteInto('store_value.attribute_id IN (?)', array_keys($_attributes)),
583592
"store_value.{$this->getLinkField()} = e.{$this->getLinkField()}",
@@ -587,18 +596,23 @@ public function getAttributeRawValue($entityId, $attribute, $store)
587596
$select->joinLeft(
588597
['store_value' => $table],
589598
implode(' AND ', $joinCondition),
590-
['attr_value' => $valueExpr]
599+
['attribute_id' => $attributeIdExpr, 'attr_value' => $valueExpr]
591600
);
592601

593602
$bind['store_id'] = $store;
594603
} else {
595-
$select->columns(['attr_value' => 'value'], 'default_value');
604+
$select->columns(
605+
['attribute_id' => 'attribute_id', 'attr_value' => 'value'],
606+
'default_value'
607+
);
596608
}
597609

598610
$result = $connection->fetchPairs($select, $bind);
599611
foreach ($result as $attrId => $value) {
600-
$attrCode = $typedAttributes[$table][$attrId];
601-
$attributesData[$attrCode] = $value;
612+
if ($attrId !== '') {
613+
$attrCode = $typedAttributes[$table][$attrId];
614+
$attributesData[$attrCode] = $value;
615+
}
602616
}
603617
}
604618
}

0 commit comments

Comments
 (0)