Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve `Order#collect_backend_payment_methods` to exclude inactive payment methods

Damian Legawiec80849f5c8aae
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index f5a58ea210..e14ee2eeae 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -642,7 +642,7 @@ module Spree
end
def collect_backend_payment_methods
- PaymentMethod.available_on_back_end.select { |pm| pm.available_for_order?(self) }
+ PaymentMethod.active.available_on_back_end.select { |pm| pm.available_for_order?(self) }
end
# determines whether the inventory is fully discounted
diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb
index 3fcbcf78b2..cc34d21564 100644
--- a/core/app/models/spree/payment_method.rb
+++ b/core/app/models/spree/payment_method.rb
@@ -10,10 +10,8 @@ module Spree
include Spree::Security::PaymentMethods
end
- scope :active, -> { where(active: true).order(position: :asc) }
- scope :available, -> { active.where(display_on: [:front_end, :back_end, :both]) }
- scope :available_on_front_end, -> { active.where(display_on: [:front_end, :both]) }
- scope :available_on_back_end, -> { active.where(display_on: [:back_end, :both]) }
+ scope :active, -> { where(active: true).order(position: :asc) }
+ scope :available, -> { active.where(display_on: [:front_end, :back_end, :both]) }
after_initialize :set_name, if: :new_record?
diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb
index 3fbeecd384..4f97608878 100644
--- a/core/spec/models/spree/order_spec.rb
+++ b/core/spec/models/spree/order_spec.rb
@@ -1224,9 +1224,11 @@ describe Spree::Order, type: :model do
let!(:order) { create(:order_with_line_items, line_items_count: 2) }
let!(:credit_card_payment_method) { create(:simple_credit_card_payment_method, display_on: 'both', stores: [store]) }
let!(:store_credit_payment_method) { create(:store_credit_payment_method, display_on: 'both', stores: [store]) }
+ let!(:inactive_payment_method) { create(:simple_credit_card_payment_method, display_on: 'both', stores: [store], active: false) }
it { expect(order.collect_backend_payment_methods).to include(credit_card_payment_method) }
it { expect(order.collect_backend_payment_methods).not_to include(store_credit_payment_method) }
+ it { expect(order.collect_backend_payment_methods).not_to include(inactive_payment_method) }
end
describe '#create_shipment_tax_charge!' do