diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 6fc2ec1ac0..ea823f06b5 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -149,11 +149,13 @@ module Spree } scope :sort_by_billing_address_name_asc, -> { - joins(:bill_address).order("spree_addresses.lastname ASC, spree_addresses.firstname ASC") + references(:bill_address) + .order("spree_addresses.lastname ASC, spree_addresses.firstname ASC") } scope :sort_by_billing_address_name_desc, -> { - joins(:bill_address).order("spree_addresses.lastname DESC, spree_addresses.firstname DESC") + references(:bill_address) + .order("spree_addresses.lastname DESC, spree_addresses.firstname DESC") } scope :with_line_items_variants_and_products_outer, lambda { diff --git a/app/services/search_orders.rb b/app/services/search_orders.rb index e9430b85ad..e8992d1b90 100644 --- a/app/services/search_orders.rb +++ b/app/services/search_orders.rb @@ -20,10 +20,7 @@ class SearchOrders ransack(params[:q]). result(distinct: true) - if ['bill_address', - 'billing_address'].any?{ |param| - params.dig(:q, :s)&.starts_with?(param) - } + if params.dig(:q, :s)&.starts_with?("bill_address_") search = search.select('spree_addresses.*, spree_orders.*') end diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 2d362a6e38..d64b74eb9d 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -277,6 +277,13 @@ describe ' # non-empty cart order, with no with bill- and ship-address appear in the results expect(page).to have_content order_not_empty_no_address.number + + # And the same orders are displayed when sorting by name: + find("th a", text: "NAME").click + + expect(page).to have_no_content order_empty.number + expect(page).to have_content order_not_empty.number + expect(page).to have_content order_not_empty_no_address.number end end