mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
change SearchOrders service to search with shipping_method
This commit is contained in:
@@ -24,13 +24,25 @@ class SearchOrders
|
||||
attr_reader :params, :current_user
|
||||
|
||||
def fetch_orders
|
||||
@search = ::Permissions::Order.new(current_user).editable_orders.ransack(params[:q])
|
||||
@search = search_query.ransack(params[:q])
|
||||
|
||||
return paginated_results if using_pagination?
|
||||
|
||||
@search.result(distinct: true)
|
||||
end
|
||||
|
||||
def search_query
|
||||
base_query = ::Permissions::Order.new(current_user).editable_orders
|
||||
return base_query unless params[:shipping_method_id]
|
||||
|
||||
base_query
|
||||
.joins(shipments: :shipping_rates)
|
||||
.where(spree_shipping_rates: {
|
||||
selected: true,
|
||||
shipping_method_id: params[:shipping_method_id]
|
||||
})
|
||||
end
|
||||
|
||||
def paginated_results
|
||||
@search.result(distinct: true)
|
||||
.page(params[:page])
|
||||
|
||||
Reference in New Issue
Block a user