mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-21 20:06:54 +00:00
Only show payment methods for the distributor of the order
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user