Only show payment methods for the distributor of the order

This commit is contained in:
David Cook
2013-08-19 12:43:45 +10:00
parent 08babeed65
commit 2d305b59d9
2 changed files with 20 additions and 10 deletions

View File

@@ -1,14 +1,20 @@
# When a user fires an event, take them back to where they came from
# Responder: http://guides.spreecommerce.com/developer/logic.html#overriding-controller-action-responses
# For some strange reason, adding PaymentsController.class_eval will cause gems/spree/app/controllers/spree/admin/payments_controller.rb:37 to error:
# payments_url not defined.
# This could be fixed by replacing line 37 with:
# respond_with(@payment, location: admin_order_payments_url) { |format| format.html { redirect_to admin_order_payments_path(@order) } }
Spree::Admin::PaymentsController.class_eval do
# When a user fires an event, take them back to where they came from
# Responder: http://guides.spreecommerce.com/developer/logic.html#overriding-controller-action-responses
# For some strange reason, adding PaymentsController.class_eval will cause gems/spree/app/controllers/spree/admin/payments_controller.rb:37 to error:
# payments_url not defined.
# This could be fixed by replacing line 37 with:
# respond_with(@payment, location: admin_order_payments_url) { |format| format.html { redirect_to admin_order_payments_path(@order) } }
respond_override :fire => { :html => { :success => lambda {
redirect_to request.referer # Keeps any filter and sort prefs
} } }
append_before_filter :filter_payment_methods
# Only show payments for the order's distributor
def filter_payment_methods
@payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor}
end
end

View File

@@ -1,6 +1,6 @@
Spree::PaymentMethod.class_eval do
belongs_to :distributor, :class_name => 'Enterprise'
validates_presence_of :distributor_id
attr_accessible :distributor_id
@@ -17,6 +17,10 @@ Spree::PaymentMethod.class_eval do
}
end
def has_distributor?(distributor)
self.distributor == distributor
end
# Ensure that all derived classes also allow distributor_id
Spree::Gateway.providers.each do |p|
p.attr_accessible :distributor_id