mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Extract payment method logic from OrderPaymentFinder into the orders helper
This commit is contained in:
@@ -9,5 +9,9 @@ module Admin
|
||||
adjustment.originator_type == "Spree::ShippingMethod"
|
||||
end
|
||||
end
|
||||
|
||||
def last_payment_method(order)
|
||||
OrderPaymentFinder.new(order).last_payment&.payment_method
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module OrderPaymentFinder
|
||||
def self.last_payment_method(order)
|
||||
class OrderPaymentFinder
|
||||
def initialize(order)
|
||||
@order = order
|
||||
end
|
||||
|
||||
def last_payment
|
||||
# `max_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(:created_at).last`. Using `last`
|
||||
@@ -9,6 +13,6 @@ module OrderPaymentFinder
|
||||
#
|
||||
# We are not using `updated_at` because all payments are touched when the
|
||||
# order is updated and then all payments have the same `updated_at` value.
|
||||
order.payments.max_by(&:created_at)&.payment_method
|
||||
@order.payments.max_by(&:created_at)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
= t :email_payment_summary
|
||||
%h4
|
||||
= t :email_payment_method
|
||||
%strong= OrderPaymentFinder.last_payment_method(@order)&.name
|
||||
%strong= last_payment_method(@order)&.name
|
||||
%p
|
||||
%em= OrderPaymentFinder.last_payment_method(@order)&.description
|
||||
%em= last_payment_method(@order)&.description
|
||||
%p
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
.pad
|
||||
.text-big
|
||||
= t :order_payment
|
||||
%strong= OrderPaymentFinder.last_payment_method(order)&.name
|
||||
%strong= last_payment_method(order)&.name
|
||||
%p.text-small.text-skinny.pre-line
|
||||
%em= OrderPaymentFinder.last_payment_method(order)&.description
|
||||
%em= last_payment_method(order)&.description
|
||||
|
||||
.order-summary.text-small
|
||||
%strong
|
||||
|
||||
Reference in New Issue
Block a user