Skip to content

Commit

Permalink
fix regression introduced in OpenMage#2993 where attributes are no lo…
Browse files Browse the repository at this point in the history
…nger sorted correctly by attribute group order in attribute comparison
  • Loading branch information
davidhiendl committed Jul 1, 2024
1 parent 1d4fe88 commit f0e8993
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,23 @@ public function getComparableAttributes()
$eavConfig = Mage::getSingleton('eav/config');
$attributeIds = $eavConfig->getAttributeSetAttributeIds($setIds);
$this->_comparableAttributes = [];
$attributeSortInfo = [];
foreach ($attributeIds as $attributeId) {
$attribute = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeId);
if ($attribute->getData('is_comparable')) {
$this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
$attributeSortInfo[$attribute->getAttributeCode()] = $eavConfig->getAttributeSetGroupInfo($attributeId, $setIds);
}
}

usort($this->_comparableAttributes, function ($a, $b) {
return $a->getPosition() - $b->getPosition();
uasort($this->_comparableAttributes, function ($a, $b) use ($attributeSortInfo) {
/** @var Mage_Eav_Model_Entity_Attribute_Abstract $a */
/** @var Mage_Eav_Model_Entity_Attribute_Abstract $b */

$aSort = $attributeSortInfo[$a->getAttributeCode()]; // contains group_id, group_sort, sort
$bSort = $attributeSortInfo[$b->getAttributeCode()]; // contains group_id, group_sort, sort

return $aSort['group_sort'] <=> $bSort['group_sort'] ?: $aSort['sort'] <=> $bSort['sort'];
});
}
}
Expand Down
21 changes: 21 additions & 0 deletions app/code/core/Mage/Eav/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,27 @@ public function getAttributeSetAttributeIds($attributeSetId)
return array_keys($attributes);
}

/**
* Return first attribute sorting information found for a given list of attribute sets
* @param int $attributeId
* @param int|int[] $attributeSetIds
* @return false|array
*/
public function getAttributeSetGroupInfo($attributeId, $attributeSetIds)
{
if (!is_array($attributeSetIds)) {
$attributeSetIds = [$attributeSetIds];
}

foreach ($attributeSetIds as $attributeSetId) {
if (isset($this->_attributeSetInfo[$attributeId][$attributeSetId])) {
return $this->_attributeSetInfo[$attributeId][$attributeSetId];
}
}

return false;
}

/**
* @param mixed $entityType
* @param string $attribute
Expand Down

0 comments on commit f0e8993

Please # to comment.