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

keep attribute_id as keys in getFilterableAttributes () #4639

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

empiricompany
Copy link
Contributor

Description (*)

I found these issues with Mirasvit_Seofilter.
getFilterableAttributes() lost its keys after being reordered by position with usort.
In my case, Mirasvit_Seofilter expects an array where the keys must contain the IDs, then it calls array_keys() to compare them with the current filter.

// get all currently filterable attributes
$category = Mage::registry('current_category');
$filterableAttributes = Mage::getSingleton('seofilter/catalog_layer')->setCurrentCategory($category)->getFilterableAttributes();
// failure, if current attribute not filterable or the option does not belong to the given attribute model
if (!in_array($option['attribute_id'], array_keys($filterableAttributes))

after reordering with usort, it lost the attribute_id and reset the key like 0,1,2,3,4...

usort($attributes, function ($a, $b) {
    return $a->getPosition() - $b->getPosition();
});

returned array must be $attributes[$attributeId] = $attribute;

Manual testing scenarios (*)

  1. call Mage_Catalog_Model_Layer::getFilterableAttributes()
  2. get array of filterable attribute ids with array_keys()

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Catalog Relates to Mage_Catalog label Feb 18, 2025
Copy link
Contributor

github-actions bot commented Feb 18, 2025

Test Results

715 tests  ±0   688 ✅ +24   3s ⏱️ ±0s
163 suites ±0    27 💤  - 24 
  1 files   ±0     0 ❌ ± 0 

Results for commit c7e2b52. ± Comparison against base commit f48b6c0.

♻️ This comment has been updated with latest results.

@sreichel sreichel added the bug label Feb 18, 2025
@sreichel sreichel added this to the 20.13.0 milestone Feb 18, 2025
Copy link
Contributor

@kiatng kiatng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref line 217: $attributes[$attributeId] = $attribute;, the intention is to have attribute_id as keys

Copy link
Contributor

@sreichel sreichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component: Catalog Relates to Mage_Catalog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants