From 49dbe1d039da1877a950e9637f7bb2d01674c239 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 15 Sep 2025 02:15:03 +0500 Subject: [PATCH] Refactor comments for clarity in product sorting concerns --- app/controllers/admin/products_v3_controller.rb | 2 +- app/models/concerns/product_sort_by_stocks.rb | 2 -- spec/models/spree/product_sort_by_stocks_spec.rb | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 221d4c46aa..6d1ae388cb 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -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| diff --git a/app/models/concerns/product_sort_by_stocks.rb b/app/models/concerns/product_sort_by_stocks.rb index c2e549c56e..f777910fd7 100644 --- a/app/models/concerns/product_sort_by_stocks.rb +++ b/app/models/concerns/product_sort_by_stocks.rb @@ -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 diff --git a/spec/models/spree/product_sort_by_stocks_spec.rb b/spec/models/spree/product_sort_by_stocks_spec.rb index a852f4b7c9..0a6e49c397 100644 --- a/spec/models/spree/product_sort_by_stocks_spec.rb +++ b/spec/models/spree/product_sort_by_stocks_spec.rb @@ -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']