Refactor comments for clarity in product sorting concerns

This commit is contained in:
Ahmed Ejaz
2025-09-15 02:15:03 +05:00
parent c326aa6b23
commit 49dbe1d039
3 changed files with 2 additions and 4 deletions

View File

@@ -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|

View File

@@ -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

View File

@@ -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']