mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Refactor duplicated distributors association in payment_method and gateway to a concern
This commit is contained in:
15
app/models/spree/concerns/payment_method_distributors.rb
Normal file
15
app/models/spree/concerns/payment_method_distributors.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
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::PaymentMethodDistributors
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
attr_accessible :distributor_ids
|
||||
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
|
||||
@@ -1,8 +1,9 @@
|
||||
require 'spree/concerns/payment_method_distributors'
|
||||
|
||||
Spree::Gateway.class_eval do
|
||||
include Spree::PaymentMethodDistributors
|
||||
|
||||
# Default to live
|
||||
preference :server, :string, :default => 'live'
|
||||
preference :test_mode, :boolean, :default => false
|
||||
|
||||
attr_accessible :distributor_ids
|
||||
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
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
require 'spree/concerns/payment_method_distributors'
|
||||
|
||||
Spree::PaymentMethod.class_eval do
|
||||
include Spree::Core::CalculatedAdjustments
|
||||
include Spree::PaymentMethodDistributors
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', :class_name => 'Enterprise', association_foreign_key: 'distributor_id'
|
||||
has_many :credit_cards, class_name: "Spree::CreditCard" # from Spree v.2.3.0 d470b31798f37
|
||||
|
||||
attr_accessible :distributor_ids, :tag_list
|
||||
attr_accessible :tag_list
|
||||
|
||||
after_initialize :init
|
||||
|
||||
|
||||
Reference in New Issue
Block a user