Merge pull request #11348 from abdellani/fix-non-empty-orders-in-cart-state-not-appearing

fix Non-empty orders in the cart state do not appear in orders page
This commit is contained in:
Konrad
2023-08-29 15:33:49 +02:00
committed by GitHub
5 changed files with 46 additions and 9 deletions

View File

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

View File

@@ -15,11 +15,16 @@ class SearchOrders
attr_reader :params, :current_user
def fetch_orders
@search = search_query.
search = search_query.
includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle).
ransack(params[:q])
ransack(params[:q]).
result(distinct: true)
@search.result(distinct: true).joins(:bill_address)
if params.dig(:q, :s)&.starts_with?("bill_address_")
search = search.select('spree_addresses.*, spree_orders.*')
end
search
end
def search_query

View File

@@ -33,7 +33,7 @@
%a{ href: "mailto:#{order.email}", target: "_blank" }
= order.email
%td
= order.bill_address.full_name_for_sorting
= order&.bill_address&.full_name_for_sorting
%td.align-center
%span
= order.display_total

View File

@@ -149,6 +149,33 @@ module Api
.map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4])
.map{ |o| o["id"] }
end
context "with an order without billing address" do
let!(:order7) {
create(:order_with_line_items, billing_address: nil, order_cycle: order_cycle,
distributor: distributor)
}
it 'can show orders without bill address' do
get :index, params: { q: {} },
as: :json
expect(json_response['orders']
.map{ |o| o[:id] }).to match_array serialized_orders([order2, order3, order1, order4,
order7])
.map{ |o|
o["id"]
}
end
it 'can sort orders by bill_address.lastname' do
get :index, params: { q: { s: 'bill_address_lastname ASC' } },
as: :json
expect(json_response['orders']
.map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4, order7])
.map{ |o| o["id"] }
end
end
end
context 'with pagination' do

View File

@@ -269,8 +269,6 @@ describe '
end
it "displays non-empty cart orders" do
pending "issue #11120"
# empty cart order does not appear in the results
expect(page).not_to have_content order_empty.number
@@ -278,8 +276,13 @@ describe '
expect(page).to have_content order_not_empty.number
# 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
# pending issue #11120
# 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