Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

SD-892 Move has_free_shipping? function into order model

Krzysztof Kalisz0ac3e7ce09bf
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 0a51e48a37..39909531bd 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -643,6 +643,13 @@ module Spree
sum(:amount)
end
+ def has_free_shipping?
+ promotions.
+ joins(:promotion_actions).
+ where(spree_promotion_actions: { type: 'Spree::Promotion::Actions::FreeShipping' }).
+ exists?
+ end
+
private
def link_by_email
diff --git a/frontend/app/helpers/spree/orders_helper.rb b/frontend/app/helpers/spree/orders_helper.rb
index 1af823ff16..17444cf105 100644
--- a/frontend/app/helpers/spree/orders_helper.rb
+++ b/frontend/app/helpers/spree/orders_helper.rb
@@ -3,12 +3,5 @@ module Spree
def order_just_completed?(order)
flash[:order_completed] && order.present?
end
-
- def order_has_free_shipping?(order)
- order.promotions.
- joins(:promotion_actions).
- where(spree_promotion_actions: { type: 'Spree::Promotion::Actions::FreeShipping' }).
- exists?
- end
end
end
diff --git a/frontend/app/views/spree/checkout/_summary.html.erb b/frontend/app/views/spree/checkout/_summary.html.erb
index e4e1f0386a..472c9724ce 100644
--- a/frontend/app/views/spree/checkout/_summary.html.erb
+++ b/frontend/app/views/spree/checkout/_summary.html.erb
@@ -27,7 +27,7 @@
<% end %>
<% if order.passed_checkout_step?("address") && order.shipments.any? %>
- <% if order_has_free_shipping?(order) %>
+ <% if order.has_free_shipping? %>
<div class="d-table-cell"><%= Spree.t(:shipping) %>:</div>
<div class="d-table-cell text-right"><%= Spree.t(:free) %></div>
<% else %>