diff --git a/app/models/concerns/payment_method_distributors.rb b/app/models/concerns/payment_method_distributors.rb new file mode 100644 index 0000000000..d9ac7ccb68 --- /dev/null +++ b/app/models/concerns/payment_method_distributors.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'active_support/concern' + +# This concern is used to duplicate the associations distributors and distributor_ids +# across payment method and gateway +# this fixes the inheritance problem https://github.com/openfoodfoundation/openfoodnetwork/issues/2781 +module PaymentMethodDistributors + extend ActiveSupport::Concern + + def self.included(base) + base.class_eval do + 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 + end +end diff --git a/app/models/spree/concerns/payment_method_distributors.rb b/app/models/spree/concerns/payment_method_distributors.rb deleted file mode 100644 index ce25c5d9b9..0000000000 --- a/app/models/spree/concerns/payment_method_distributors.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'active_support/concern' - -# This concern is used to duplicate the associations distributors and distributor_ids -# across payment method and gateway -# this fixes the inheritance problem https://github.com/openfoodfoundation/openfoodnetwork/issues/2781 -module Spree - module PaymentMethodDistributors - extend ActiveSupport::Concern - - def self.included(base) - base.class_eval do - 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 - end - end -end diff --git a/app/models/spree/gateway.rb b/app/models/spree/gateway.rb index 216f0cfe6b..99d57826fb 100644 --- a/app/models/spree/gateway.rb +++ b/app/models/spree/gateway.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -require 'spree/concerns/payment_method_distributors' - module Spree class Gateway < PaymentMethod - include Spree::PaymentMethodDistributors + include PaymentMethodDistributors delegate_belongs_to :provider, :authorize, :purchase, :capture, :void, :credit diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index 39df36486d..9c41fbefa2 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -require 'spree/concerns/payment_method_distributors' - module Spree class PaymentMethod < ActiveRecord::Base include Spree::Core::CalculatedAdjustments - include Spree::PaymentMethodDistributors + include PaymentMethodDistributors acts_as_taggable acts_as_paranoid