diff --git a/app/models/spree/gateway_decorator.rb b/app/models/spree/gateway_decorator.rb new file mode 100644 index 0000000000..e40b260ae8 --- /dev/null +++ b/app/models/spree/gateway_decorator.rb @@ -0,0 +1,10 @@ +Spree::Gateway.class_eval do + + # Due to class load order, when config.cache_classes is enabled (ie. staging and production + # environments), this association isn't inherited from PaymentMethod. As a result, creating + # payment methods using payment gateways results in: + # undefined method `association_class' for nil:NilClass + # To avoid that, we redefine this association here. + + has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', :class_name => 'Enterprise', foreign_key: 'payment_method_id', association_foreign_key: 'distributor_id' +end diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index 8e696989a4..ddbc0251a9 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -1,4 +1,5 @@ Spree::PaymentMethod.class_eval do + # See gateway_decorator.rb when modifying this association has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', :class_name => 'Enterprise', association_foreign_key: 'distributor_id' attr_accessible :distributor_ids