From 3ffe732b3057bfa28e847eef2534df88ac7d3842 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 19 Aug 2013 12:51:49 +1000 Subject: [PATCH] Ensure valid payment method is selected --- .../spree/admin/payments_controller_decorator.rb | 1 + app/models/spree/payment_method_decorator.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/payments_controller_decorator.rb b/app/controllers/spree/admin/payments_controller_decorator.rb index 35237d3e76..23db5eca09 100644 --- a/app/controllers/spree/admin/payments_controller_decorator.rb +++ b/app/controllers/spree/admin/payments_controller_decorator.rb @@ -15,6 +15,7 @@ Spree::Admin::PaymentsController.class_eval do # Only show payments for the order's distributor def filter_payment_methods @payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor} + @payment_method ||= @payment_methods.first end end diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index 1f19d9498c..0f52a4e291 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -15,10 +15,10 @@ Spree::PaymentMethod.class_eval do where('distributor_id IN (?)', user.enterprises.map {|enterprise| enterprise.id }) end } -end -def has_distributor?(distributor) - self.distributor == distributor + def has_distributor?(distributor) + self.distributor == distributor + end end # Ensure that all derived classes also allow distributor_id