Created
October 14, 2010 22:10
-
-
Save kakra/627180 to your computer and use it in GitHub Desktop.
Filter payment methods in Spree depending on the shipping name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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