From 3e0a5bac6a7e44e1dee4837b2c086fddde105f0a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 18 Feb 2020 10:40:58 +1100 Subject: [PATCH] Move helper to service for re-use --- .../orders_helper.rb => services/order_payment_finder.rb} | 6 ++++-- app/views/spree/shared/_order_details.html.haml | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) rename app/{helpers/orders_helper.rb => services/order_payment_finder.rb} (78%) diff --git a/app/helpers/orders_helper.rb b/app/services/order_payment_finder.rb similarity index 78% rename from app/helpers/orders_helper.rb rename to app/services/order_payment_finder.rb index ae94325a83..7011941cf7 100644 --- a/app/helpers/orders_helper.rb +++ b/app/services/order_payment_finder.rb @@ -1,5 +1,7 @@ -module OrdersHelper - def order_paid_via(order) +# frozen_string_literal: true + +module OrderPaymentFinder + def self.last_payment_method(order) # `sort_by` avoids additional database queries when payments are loaded # already. There is usually only one payment and this shouldn't cause # any overhead compared to `order(:updated_at)`. diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index 0a42574432..2a9c6ee266 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -13,9 +13,9 @@ .pad .text-big = t :order_payment - %strong= order_paid_via(order).andand.name + %strong= OrderPaymentFinder.last_payment_method(order).andand.name %p.text-small.text-skinny.pre-line - %em= order_paid_via(order).andand.description + %em= OrderPaymentFinder.last_payment_method(order).andand.description .order-summary.text-small %strong