diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 0fa95863e0..d5b7271589 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -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 diff --git a/app/helpers/spree/payment_methods_helper.rb b/app/helpers/spree/payment_methods_helper.rb index bfd4a72e26..ac6b16127c 100644 --- a/app/helpers/spree/payment_methods_helper.rb +++ b/app/helpers/spree/payment_methods_helper.rb @@ -11,7 +11,7 @@ module Spree end def payment_method_name(payment) - payment_method(payment)&.name + payment_method(payment)&.display_name end end end diff --git a/app/models/invoice/data_presenter/payment.rb b/app/models/invoice/data_presenter/payment.rb index bf63fe21d4..80b140d139 100644 --- a/app/models/invoice/data_presenter/payment.rb +++ b/app/models/invoice/data_presenter/payment.rb @@ -18,7 +18,7 @@ class Invoice end def payment_method_name - payment_method&.name + payment_method&.display_name end end end diff --git a/app/models/invoice/data_presenter/payment_method.rb b/app/models/invoice/data_presenter/payment_method.rb index 4eeb014443..3843476d7d 100644 --- a/app/models/invoice/data_presenter/payment_method.rb +++ b/app/models/invoice/data_presenter/payment_method.rb @@ -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 diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index d1473a3963..b3a32ca340 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -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 diff --git a/app/serializers/invoice/payment_method_serializer.rb b/app/serializers/invoice/payment_method_serializer.rb index 2af24e0a6e..ccc96008c7 100644 --- a/app/serializers/invoice/payment_method_serializer.rb +++ b/app/serializers/invoice/payment_method_serializer.rb @@ -2,6 +2,6 @@ class Invoice class PaymentMethodSerializer < ActiveModel::Serializer - attributes :id, :name, :description + attributes :id, :display_name, :display_description end end diff --git a/app/views/admin/customer_account_transaction/index.turbo_stream.haml b/app/views/admin/customer_account_transaction/index.turbo_stream.haml index 124a113690..d0419dd982 100644 --- a/app/views/admin/customer_account_transaction/index.turbo_stream.haml +++ b/app/views/admin/customer_account_transaction/index.turbo_stream.haml @@ -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 diff --git a/app/views/admin/enterprises/form/_payment_methods.html.haml b/app/views/admin/enterprises/form/_payment_methods.html.haml index 40ba585ab5..d19ff0c1d1 100644 --- a/app/views/admin/enterprises/form/_payment_methods.html.haml +++ b/app/views/admin/enterprises/form/_payment_methods.html.haml @@ -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 diff --git a/app/views/admin/order_cycles/checkout_options.html.haml b/app/views/admin/order_cycles/checkout_options.html.haml index 0e43eb9e07..4931ca5331 100644 --- a/app/views/admin/order_cycles/checkout_options.html.haml +++ b/app/views/admin/order_cycles/checkout_options.html.haml @@ -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 diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index 7d7761f560..b4c52c0100 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -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 } diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index f635f6d694..4a897f5651 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -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 diff --git a/app/views/spree/admin/orders/_invoice/_payment.html.haml b/app/views/spree/admin/orders/_invoice/_payment.html.haml index 81a974965a..3225370582 100644 --- a/app/views/spree/admin/orders/_invoice/_payment.html.haml +++ b/app/views/spree/admin/orders/_invoice/_payment.html.haml @@ -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 diff --git a/app/views/spree/admin/payment_methods/edit.html.haml b/app/views/spree/admin/payment_methods/edit.html.haml index ca9c2fcd26..c29107df1b 100644 --- a/app/views/spree/admin/payment_methods/edit.html.haml +++ b/app/views/spree/admin/payment_methods/edit.html.haml @@ -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' diff --git a/app/views/spree/admin/payment_methods/index.html.haml b/app/views/spree/admin/payment_methods/index.html.haml index 61eb28c63a..6a71ab2df2 100644 --- a/app/views/spree/admin/payment_methods/index.html.haml +++ b/app/views/spree/admin/payment_methods/index.html.haml @@ -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 diff --git a/app/views/spree/admin/payments/_form.html.haml b/app/views/spree/admin/payments/_form.html.haml index af699413de..86d81a0937 100644 --- a/app/views/spree/admin/payments/_form.html.haml +++ b/app/views/spree/admin/payments/_form.html.haml @@ -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}"} diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index 0038ea7309..c57519b2b7 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -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) diff --git a/app/views/spree/shared/_payment.html.haml b/app/views/spree/shared/_payment.html.haml index 0c1bc8c8d0..49e6b5b7af 100644 --- a/app/views/spree/shared/_payment.html.haml +++ b/app/views/spree/shared/_payment.html.haml @@ -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 diff --git a/app/views/spree/users/_customer_account_transactions.html.haml b/app/views/spree/users/_customer_account_transactions.html.haml index bcce135486..269fbe277f 100644 --- a/app/views/spree/users/_customer_account_transactions.html.haml +++ b/app/views/spree/users/_customer_account_transactions.html.haml @@ -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 diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index f01386a57e..9b0a72e761 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -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 diff --git a/spec/system/admin/invoice_print_spec.rb b/spec/system/admin/invoice_print_spec.rb index 9b5375b4c6..0b7d320bb2 100644 --- a/spec/system/admin/invoice_print_spec.rb +++ b/spec/system/admin/invoice_print_spec.rb @@ -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