Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed regression introduced in #2993 where attributes are no longer sorted correctly by attribute group order in attribute comparison #4064

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading