Skip to content

Sort shopfront category filter buttons alphabetically, or by enterprise preference#14487

Open
BethanOFN wants to merge 2 commits into
openfoodfoundation:masterfrom
BethanOFN:534-sort-product-category-shopfront-filters
Open

Sort shopfront category filter buttons alphabetically, or by enterprise preference#14487
BethanOFN wants to merge 2 commits into
openfoodfoundation:masterfrom
BethanOFN:534-sort-product-category-shopfront-filters

Conversation

@BethanOFN

@BethanOFN BethanOFN commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Category filter buttons on the shopfront were displayed in arbitrary database-ID order — neither alphabetical nor consistent with the "Sort by category" preference in Shop Preferences.
  • Two bugs caused this: the /api/v0/order_cycles/:id/taxons.json endpoint had no ORDER BY, and the frontend stored taxons in a plain JS object (integer-indexed keys always iterate in ascending numeric order in JS, destroying any API-provided ordering).
  • Fix: sort taxons alphabetically by default in the API response, or by preferred_shopfront_taxon_order when the distributor has "by category" sorting configured. Change supplied_taxons from a hash to an array in the products controller to preserve the sort order. Update filter_selector to handle array input alongside the existing hash input used by properties.

Closes openfoodfoundation/wishlist#534

Test plan

  • Start the dev server and visit a shopfront with multiple product categories — confirm filter buttons appear in no apparent order (currently sorted by database id)
  • In Shop Preferences, set "Sort by category" with a custom category order — confirm the filter buttons match that order after 30s delay
  • Confirm property and producer property filter buttons still display correctly (they remain hashes, handled by the existing code path in filter_selector)
  • bundle exec rspec spec/controllers/api/v0/order_cycles_controller_spec.rb — all 23 examples pass

…se preference

Category filters on the shopfront were displayed in arbitrary database-ID
order. Two bugs caused this: the taxons API endpoint had no ORDER BY, and
the frontend stored taxons in a plain JS object (integer keys always iterate
in ascending ID order, destroying any API-provided ordering).

Fix: sort taxons in the API response alphabetically by default, or by
preferred_shopfront_taxon_order when the distributor has by_category sorting
configured. Change supplied_taxons from a hash to an array in the products
controller so the API sort order is preserved. Update filter_selector to
handle array input alongside the existing hash input used by properties.
@sigmundpetersen sigmundpetersen added the ai AI generated or assisted PR/Issue label Jun 30, 2026
@BethanOFN BethanOFN requested a review from rioug July 2, 2026 13:24
@BethanOFN BethanOFN moved this from All the things 💤 to Code review 🔎 in OFN Delivery board Jul 7, 2026
@BethanOFN BethanOFN added the user facing changes Thes pull requests affect the user experience label Jul 7, 2026
@BethanOFN BethanOFN moved this from Code review 🔎 to In Progress ⚙ in OFN Delivery board Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai AI generated or assisted PR/Issue user facing changes Thes pull requests affect the user experience

Projects

Status: In Progress ⚙

Development

Successfully merging this pull request may close these issues.

Sort product category filters on shopfront as defined in Shop Preferences

2 participants