Sort filter values in a locale aware way#1262
Open
boo-code wants to merge 2 commits into
Open
Conversation
Feature filter values were ordered with natcasesort(), which compares strings byte by byte. Multi-byte accented characters (Czech č, š, ř, etc.) therefore sorted after every plain ASCII letter instead of next to their base letter, so a value like "Černá" ended up at the bottom of the list rather than near "Czech". Use a Collator built from the current language locale when the intl extension is available, with a secondary strength (case insensitive, like before) and numeric collation (to keep the natural 2-before-10 ordering). Fall back to natcasesort() when intl is not present.
|
Hello @boo-code! This is your first pull request on ps_facetedsearch repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
kpodemski
previously approved these changes
Jul 6, 2026
Contributor
|
thanks @boo-code CI is red. Details: |
getValuesCollator() read $this->context->language->locale unconditionally, so any call path where the language carries no locale raised an Undefined property notice (surfaced by the existing BlockTest fixtures, whose context language has no locale). Guard the access and fall back to natcasesort when no locale is set, which also protects a real store whose language has an empty locale configured.
Contributor
Author
|
Thanks for catching that. Fixed in f51ef4d: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
natcasesort()(inFilters\Block::sortFeatureBlock()), which compares strings byte by byte. Multi-byte accented characters (Czechč,š,ř, …) therefore sorted after every plain ASCII letter instead of next to their base letter, so e.g.Černálanded at the bottom of the list rather than right afterCzech. The fix sorts with aCollatorbuilt from the current language locale (when theintlextension is available), using a secondary strength (case-insensitive, asnatcasesortwas) and numeric collation (to keep the natural2-before-10ordering). It falls back tonatcasesort()whenintlis unavailable.BlockTest::testSortFeatureBlockSortsValuesLocaleAware): with localecs-CZ, a feature whose values areValue, Else, Beta, Černá, Czech, Other, Alphais sorted toAlpha, Beta, Czech, Černá, Else, Other, Value(red before / green after). Manually: create a feature with Czech accented values (č,š,ř, …), enable it as a filter, and check the storefront filter block — the values are now alphabetically ordered per the language instead of pushing accented ones to the end.Reported by @Hlavtox. Verified that
Collator(cs-CZ)reproduces the exact expected order from the issue (Alpha, Beta, Czech, Černá, Else, Other, Value), whereasnatcasesort()producesAlpha, Beta, Czech, Else, Other, Value, Černá.