Use display_name and display_description for payment method

This commit is contained in:
Gaetan Craig-Riou
2026-02-10 11:33:06 +11:00
parent 5bdb6e6d69
commit 152fd15bd0
20 changed files with 41 additions and 28 deletions

View File

@@ -17,7 +17,7 @@ module ReportsHelper
next unless payment_method
[payment_method.name, payment_method.id]
[payment_method.display_name, payment_method.id]
end.compact.uniq
end

View File

@@ -11,7 +11,7 @@ module Spree
end
def payment_method_name(payment)
payment_method(payment)&.name
payment_method(payment)&.display_name
end
end
end

View File

@@ -18,7 +18,7 @@ class Invoice
end
def payment_method_name
payment_method&.name
payment_method&.display_name
end
end
end

View File

@@ -3,7 +3,7 @@
class Invoice
class DataPresenter
class PaymentMethod < Invoice::DataPresenter::Base
attributes :id, :name, :description
attributes :id, :display_name, :display_description
invoice_generation_attributes :id
end
end

View File

@@ -136,9 +136,9 @@ module Spree
end
def try_translating(value)
I18n.t!(value)
rescue I18n::MissingTranslationData
value
return value if value.blank?
I18n.t(value, default: value)
end
end
end

View File

@@ -2,6 +2,6 @@
class Invoice
class PaymentMethodSerializer < ActiveModel::Serializer
attributes :id, :name, :description
attributes :id, :display_name, :display_description
end
end

View File

@@ -24,7 +24,7 @@
%td.description
= transaction.description
%td.payment-method
= t(transaction.payment_method.name.to_s)
= transaction.payment_method.display_name
%td.amount
= Spree::Money.new(transaction.amount)
%td.running_balance

View File

@@ -11,7 +11,7 @@
%tbody
- @payment_methods.each do |payment_method|
%tr
%td= payment_method.name
%td= payment_method.display_name
%td= f.check_box :payment_method_ids, { multiple: true }, payment_method.id, nil
%td= link_to t(:edit), edit_admin_payment_method_path(payment_method)
%br

View File

@@ -68,11 +68,11 @@
@order_cycle.distributor_payment_methods.include?(distributor_payment_method),
id: "order_cycle_selected_distributor_payment_method_ids_#{distributor_payment_method.id}",
data: ({ "checked-target" => "checkbox" } if distributor_payment_method.payment_method.frontend?)
= distributor_payment_method.payment_method.name
= distributor_payment_method.payment_method.display_name
- distributor.payment_methods.inactive_or_backend.each do |payment_method|
%label.disabled
= check_box_tag nil, nil, false, disabled: true
= payment_method.name
= payment_method.display_name
= "(#{t('.back_end')})"
- if distributor.payment_methods.available.none?
%p

View File

@@ -23,13 +23,13 @@
"data-action": "paymentmethod#selectPaymentMethod",
"data-paymentmethod-id": "#{payment_method.id}",
"data-paymentmethod-target": "input"
= f.label :payment_method_id, "#{payment_method.name}", for: "payment_method_#{payment_method.id}"
= f.label :payment_method_id, "#{payment_method.display_name}", for: "payment_method_#{payment_method.id}"
%em.fees=payment_or_shipping_price(payment_method, @order)
.paymentmethod-container{"data-paymentmethod-id": "#{payment_method.id}", style: "display: #{payment_method.id == selected_payment_method ? "block" : "none"}"}
- if payment_method.description && !payment_method.description.empty?
.paymentmethod-description.panel
= simple_format(html_escape(payment_method.description))
= simple_format(html_escape(payment_method.display_description))
.paymentmethod-form
= render partial: "checkout/payment/#{payment_method.method_type}", locals: { payment_method: payment_method, f: f }

View File

@@ -30,7 +30,7 @@
- payment_method = last_payment_method(@order)
%div
- if payment_method
= payment_method.name
= payment_method.display_name
%em.fees
= payment_or_shipping_price(payment_method, @order)
- elsif @order.zero_priced_order?
@@ -41,7 +41,7 @@
.summary-subtitle
= t("checkout.step3.payment_method.instructions")
%div
= payment_method&.description
= payment_method&.display_description
.checkout-substep

View File

@@ -17,4 +17,4 @@
%p.callout{style: "margin-top: 40px"}
%strong
= t :email_payment_description
%p{style: "margin: 5px"}= @order.last_payment_method.description
%p{style: "margin: 5px"}= @order.last_payment_method.display_description

View File

@@ -4,7 +4,7 @@
- content_for :page_title do
= t('.editing_payment_method')
%i.icon-arrow-right
= @payment_method.name
= @payment_method.display_name
- content_for :page_actions do
%li
= button_link_to t('.new'), spree.new_admin_payment_method_path, icon: 'icon-plus'

View File

@@ -32,7 +32,7 @@
%tbody
- @payment_methods.each do |method|
%tr{class: "#{cycle('odd', 'even')}", id: "#{spree_dom_id method}"}
%td.align-center= method.name
%td.align-center= method.display_name
%td.align-center
- method.distributors.each do |distributor|
= distributor.name

View File

@@ -14,7 +14,7 @@
%li
%label
= radio_button_tag 'payment[payment_method_id]', method.id, method == @payment_method, { class: "payment_methods_radios", "ng-model" => 'form_data.payment_method' }
= t(method.name, scope: :payment_methods, default: method.name)
= method.display_name
.payment-method-settings
- @payment_methods.each do |method|
.payment-methods{id: "payment_method_#{method.id}"}

View File

@@ -15,9 +15,9 @@
- if (order_payment_method = last_payment_method(order))
.text-big
= t :order_payment
%strong= order_payment_method&.name
%strong= order_payment_method&.display_name
%p.text-small.text-skinny.pre-line.word-wrap
%em= order_payment_method&.description
%em= order_payment_method&.display_description
- else
.text-big
= t(:no_payment_required)

View File

@@ -17,4 +17,4 @@
%p.callout{style: "margin-top: 40px"}
%strong
= t :email_payment_description
%p{style: "margin: 5px"}= last_payment_method(@order).description
%p{style: "margin: 5px"}= last_payment_method(@order).display_description

View File

@@ -38,7 +38,7 @@
%td.order2
= transaction.description
%td.order3
= t(transaction.payment_method.name.to_s)
= transaction.payment_method.display_name
%td.order4
= Spree::Money.new(transaction.amount)
%td.order5

View File

@@ -208,5 +208,13 @@ RSpec.describe Spree::PaymentMethod do
)
end
end
context "when description is empty" do
let(:description) { "" }
it "falls back to no translation" do
expect(subject.display_description).to eq("")
end
end
end
end

View File

@@ -104,9 +104,14 @@ RSpec.describe '
order.payments << create(:payment, :completed, order:,
payment_method: payment_method1,
created_at: 2.days.ago)
order.payments << create(:payment, :completed, order:,
payment_method: payment_method2,
created_at: 1.day.ago)
# Use an internal payment method so we also test the name translation
order.payments << create(
:payment,
:completed,
order:,
payment_method: Spree::PaymentMethod.customer_credit,
created_at: 1.day.ago
)
order.save!
end
@@ -115,7 +120,7 @@ RSpec.describe '
visit spree.print_admin_order_path(order, params: url_params)
convert_pdf_to_page
expect(page).to have_content 'Payment Description at Checkout'
expect(page).to have_content 'description2'
expect(page).to have_content 'Customer credit'
end
end
end