Module: Spree::MultiStore::PaymentMethodDecorator
- Defined in:
- app/models/spree/multi_store/payment_method_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#available_for_store?(store) ⇒ Boolean
Core checks the singular
store_idFK; with multi-store sharing a payment method can belong to several stores, so test membership of the join table instead.
Class Method Details
.prepended(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/spree/multi_store/payment_method_decorator.rb', line 4 def self.prepended(base) # Single-store core sets +belongs_to :store+ on PaymentMethod; this gem # layers +has_many :stores+ back on top through the legacy join table. # Core no longer declares this association, so it must live here — # without it +Spree::MultiStoreResource#set_default_store+ has no # +:stores+ reflection to build the join through. base.has_many :store_payment_methods, class_name: 'Spree::StorePaymentMethod', inverse_of: :payment_method base.has_many :stores, through: :store_payment_methods, class_name: 'Spree::Store' base.scope :for_store, ->(store) { joins(:store_payment_methods).where(StorePaymentMethod.table_name => { store_id: store.id }) } base.whitelisted_ransackable_associations = (base.whitelisted_ransackable_associations.to_a + %w[stores store_payment_methods]).uniq base.include Spree::MultiStoreResource end |
Instance Method Details
#available_for_store?(store) ⇒ Boolean
Core checks the singular store_id FK; with multi-store sharing a
payment method can belong to several stores, so test membership of the
join table instead.
24 25 26 27 28 |
# File 'app/models/spree/multi_store/payment_method_decorator.rb', line 24 def available_for_store?(store) return true if store.blank? store_ids.include?(store.id) end |