Move payment method display logic to helper

So we don't need to convert strings into classes to then only convert it
into the same string again.
This commit is contained in:
Maikel Linke
2026-01-13 14:16:38 +11:00
parent ac1dd74e23
commit 283d13eb35
4 changed files with 17 additions and 3 deletions

View File

@@ -138,7 +138,7 @@ module Spree
providers.delete("Spree::Gateway::StripeSCA") unless show_stripe?
providers.map(&:constantize)
providers
end
# Show Stripe as an option if enabled, or if the

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
module Spree
module Admin
module PaymentMethodsHelper
def payment_method_type_name(class_name)
scope = "spree.admin.payment_methods.providers"
key = class_name.demodulize.downcase
I18n.t(key, scope:)
end
end
end
end

View File

@@ -3,6 +3,6 @@
.alpha.four.columns
= label :payment_method, :type, t('.provider')
.omega.twelve.columns
= collection_select(:payment_method, :type, @providers, :to_s, :clean_name, {}, { class: 'select2 fullwidth', 'provider-prefs-for' => "#{@object.id}"})
= select(:payment_method, :type, @providers.map { |p| [payment_method_type_name(p), p] }, {}, { class: 'select2 fullwidth', 'provider-prefs-for' => "#{@object.id}"})
%div{"ng-include" => "include_html" }

View File

@@ -37,7 +37,7 @@
- method.distributors.each do |distributor|
= distributor.name
%br/
%td= method.class.clean_name
%td= payment_method_type_name(method.class.name)
- if spree_current_user.admin?
%td.align-center= method.environment.to_s.titleize
%td.align-center= method.display_on.blank? ? t('.both') : t('.' + method.display_on.to_s)