mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Refactor comments for clarity in product sorting concerns
This commit is contained in:
@@ -163,7 +163,7 @@ module Admin
|
||||
.editable_products.merge(product_scope_with_includes).ransack(ransack_query).result
|
||||
|
||||
# Postgres requires ORDER BY expressions to appear in the SELECT list when using DISTINCT.
|
||||
# If the current ransack sort uses the computed stock columns, include them in the select
|
||||
# When the current ransack sort uses the computed stock columns, include them in the select
|
||||
# so the generated COUNT/DISTINCT query is valid.
|
||||
sort_columns = Array(@q && @q[:s]).flatten
|
||||
if sort_columns.any? { |s|
|
||||
|
||||
@@ -24,12 +24,10 @@ module ProductSortByStocks
|
||||
attr_reader :on_hand_sql, :backorderable_priority_sql
|
||||
end
|
||||
|
||||
# Ransacker for ordering by stock levels
|
||||
ransacker :on_hand do
|
||||
@on_hand_sql
|
||||
end
|
||||
|
||||
# Ransacker for backorderable status (used for complex sorting)
|
||||
ransacker :backorderable_priority do
|
||||
@backorderable_priority_sql
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ RSpec.describe 'ProductSortByStocks' do
|
||||
mid.variants.first.stock_items.update_all(count_on_hand: 5)
|
||||
high.variants.first.stock_items.update_all(count_on_hand: 10)
|
||||
|
||||
# But make 'mid' backorderable so it should be sorted before 'low' when backorderable_priority asc
|
||||
# Make 'mid' backorderable so it sorts before 'low' in backorderable_priority asc
|
||||
mid.variants.first.stock_items.update_all(backorderable: true)
|
||||
|
||||
# Controller transforms 'on_hand asc' into ['backorderable_priority asc', 'on_hand asc']
|
||||
|
||||
Reference in New Issue
Block a user