Skip to content

Commit f0e8993

Browse files
committed
fix regression introduced in OpenMage#2993 where attributes are no longer sorted correctly by attribute group order in attribute comparison
1 parent 1d4fe88 commit f0e8993

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

app/code/core/Mage/Catalog/Model/Resource/Product/Compare/Item/Collection.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,23 @@ public function getComparableAttributes()
215215
$eavConfig = Mage::getSingleton('eav/config');
216216
$attributeIds = $eavConfig->getAttributeSetAttributeIds($setIds);
217217
$this->_comparableAttributes = [];
218+
$attributeSortInfo = [];
218219
foreach ($attributeIds as $attributeId) {
219220
$attribute = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeId);
220221
if ($attribute->getData('is_comparable')) {
221222
$this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
223+
$attributeSortInfo[$attribute->getAttributeCode()] = $eavConfig->getAttributeSetGroupInfo($attributeId, $setIds);
222224
}
223225
}
224226

225-
usort($this->_comparableAttributes, function ($a, $b) {
226-
return $a->getPosition() - $b->getPosition();
227+
uasort($this->_comparableAttributes, function ($a, $b) use ($attributeSortInfo) {
228+
/** @var Mage_Eav_Model_Entity_Attribute_Abstract $a */
229+
/** @var Mage_Eav_Model_Entity_Attribute_Abstract $b */
230+
231+
$aSort = $attributeSortInfo[$a->getAttributeCode()]; // contains group_id, group_sort, sort
232+
$bSort = $attributeSortInfo[$b->getAttributeCode()]; // contains group_id, group_sort, sort
233+
234+
return $aSort['group_sort'] <=> $bSort['group_sort'] ?: $aSort['sort'] <=> $bSort['sort'];
227235
});
228236
}
229237
}

app/code/core/Mage/Eav/Model/Config.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,27 @@ public function getAttributeSetAttributeIds($attributeSetId)
598598
return array_keys($attributes);
599599
}
600600

601+
/**
602+
* Return first attribute sorting information found for a given list of attribute sets
603+
* @param int $attributeId
604+
* @param int|int[] $attributeSetIds
605+
* @return false|array
606+
*/
607+
public function getAttributeSetGroupInfo($attributeId, $attributeSetIds)
608+
{
609+
if (!is_array($attributeSetIds)) {
610+
$attributeSetIds = [$attributeSetIds];
611+
}
612+
613+
foreach ($attributeSetIds as $attributeSetId) {
614+
if (isset($this->_attributeSetInfo[$attributeId][$attributeSetId])) {
615+
return $this->_attributeSetInfo[$attributeId][$attributeSetId];
616+
}
617+
}
618+
619+
return false;
620+
}
621+
601622
/**
602623
* @param mixed $entityType
603624
* @param string $attribute

0 commit comments

Comments
 (0)