Skip to content

Instantly share code, notes, and snippets.

@kakra
Created October 14, 2010 22:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kakra/627180 to your computer and use it in GitHub Desktop.
Save kakra/627180 to your computer and use it in GitHub Desktop.
Filter payment methods in Spree depending on the shipping name
# Filter payment methods in Spree depending on the shipping name,
# use the following snippet within your activation method to
# make it work:
#
# CheckoutsController.class_eval { include FilterPaymentMethods }
#
# The magic happens within the InstanceMethods module, change the
# regexp to fit your needs.
#
# Kai Krakow, http://github.com/kakra
# provided as-is
module FilterPaymentMethods
def self.included(base)
base.send :include, InstanceMethods
base.instance_eval do
alias_method_chain :load_available_payment_methods, :filter_by_shipping
end
end
module InstanceMethods
private
def load_available_payment_methods_with_filter_by_shipping
load_available_payment_methods_without_filter_by_shipping
shipping_name = @checkout.try(:shipping_method).try(:name)
if shipping_name.match /Nachnahme/
@payment_methods.reject! {|pm| !pm.name.match /Nachnahme/ }
else
@payment_methods.reject! {|pm| pm.name.match /Nachnahme/ }
end
@payment_mentod = @payment_methods.first unless @payment_methods.include? @payment_method
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment