From 3d44f4bc98c5f7a82e09da91795781e878e690b6 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:09:54 +0100 Subject: [PATCH] Introduce "zero priced order" concept with no required payment This applies to cases where an order contains items with zero price or where applied vouchers have reduced the order's total to zero. --- app/models/spree/order.rb | 8 +++++++- app/views/spree/shared/_order_details.html.haml | 14 +++++++++----- config/locales/en.yml | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 91c70e8c84..d87b14b3bb 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -23,7 +23,7 @@ module Spree go_to_state :delivery go_to_state :payment, if: ->(order) { order.update_totals - order.payment_required? + order.payment_required? || order.zero_priced_order? } go_to_state :confirmation go_to_state :complete @@ -219,6 +219,12 @@ module Spree total.to_f > 0.0 && !skip_payment_for_subscription? end + # There are items present in the order, but either the items have zero price, + # or the order's total has been modified (maybe discounted) to zero. + def zero_priced_order? + valid? && line_items.count.positive? && total.zero? + end + # Returns the relevant zone (if any) to be used for taxation purposes. # Uses default tax zone unless there is a specific match def tax_zone diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index b559074bf5..b3e5650984 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -11,11 +11,15 @@ %strong = order.display_total.to_html .pad - .text-big - = t :order_payment - %strong= last_payment_method(order)&.name - %p.text-small.text-skinny.pre-line.word-wrap - %em= last_payment_method(order)&.description + - if (order_payment_method = last_payment_method(order)) + .text-big + = t :order_payment + %strong= order_payment_method&.name + %p.text-small.text-skinny.pre-line.word-wrap + %em= order_payment_method&.description + - else + .text-big + = t(:no_payment_required) .order-summary.text-small %strong diff --git a/config/locales/en.yml b/config/locales/en.yml index 22acda77a9..5f39fb8b57 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2120,6 +2120,7 @@ en: order_not_paid: NOT PAID order_total: Total order order_payment: "Paying via:" + no_payment_required: "No payment required" order_billing_address: Billing address order_delivery_on: Delivery on order_delivery_address: Delivery address