266: Updating to incorporate Rohans suggestions. Searching on payment method name rather than id

This commit is contained in:
Lynne Davis
2014-11-12 11:47:26 +00:00
parent 6f6ae309c6
commit 932d571d2c
4 changed files with 15 additions and 12 deletions

View File

@@ -13,14 +13,12 @@ module Spree
#I don't like that this is done in two loops, but redundant list entries
# were created otherwise...
def report_payment_method_options(orders)
payment_method_list = {}
orders.map do |o|
payment_method_name = o.payments.first.payment_method.andand.name
payment_method_id = o.payments.first.payment_method.andand.id
payment_method_list[payment_method_name] = payment_method_id
payment_method_list = []
orders.map do |o|
payment_method_list << o.payments.first.payment_method.andand.name
end
payment_method_list.each do |key, value|
[ "#{value}".html_safe, key]
payment_method_list.uniq.each do |pm|
[ "#{pm}".html_safe, pm]
end
end

View File

@@ -66,6 +66,12 @@ Spree::Order.class_eval do
where("state != ?", state)
}
scope :with_payment_method_name, lambda { |payment_method_name|
joins(:payments => :payment_method).
where('spree_payment_methods.name = ?', payment_method_name).
select('DISTINCT spree_orders.*')
}
# -- Methods
def products_available_from_new_distribution

View File

@@ -9,8 +9,8 @@
= label_tag nil, "Payment Methods (hold Ctrl to select multiple payment methods)"
%br
= select_tag(:payment_method_id,
options_for_select(report_payment_method_options(@orders), params[:payment_method_id]),
= select_tag(:payment_method_name,
options_for_select(report_payment_method_options(@orders), params[:payment_method_name]),
multiple: true, include_blank: true)
%br
%br

View File

@@ -43,9 +43,8 @@ module OpenFoodNetwork
end
def filter_to_payment_method (orders)
if params.has_key? (:payment_method_id)
orders.joins(:payments)
.where(:spree_payments => {:payment_method_id => params[:payment_method_id]} )
if params.has_key? (:payment_method_name)
orders.with_payment_method_name(params[:payment_method_name])
else
orders
end