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.

Fixed: don't crash order view when order doesn't have any addresses (#13173)

Damian Legawiec997e643e06e7
diff --git a/storefront/app/views/themes/default/spree/shared/_order_details.html.erb b/storefront/app/views/themes/default/spree/shared/_order_details.html.erb
index b2f7d9b725..3b48d336b7 100644
--- a/storefront/app/views/themes/default/spree/shared/_order_details.html.erb
+++ b/storefront/app/views/themes/default/spree/shared/_order_details.html.erb
@@ -37,24 +37,28 @@
<div class="mt-6 bg-accent mb-24">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4 lg:gap-6 p-4 lg:p-6 text-sm bg-border bg-accent-100">
- <!-- billing address -->
- <div>
- <div class="uppercase tracking-widest mb-2">
- <%= Spree.t(:billing_address) %>
- </div>
- <div class="!leading-[1.375rem] text-neutral-800">
- <%= render 'spree/shared/address', address: order.billing_address %>
- </div>
- </div>
- <!-- payment into -->
- <div class="mb-5 lg:mb-0">
- <div class="uppercase tracking-widest mb-2">
- <%= Spree.t(:payment_information) %>
+ <% if order.billing_address.present? %>
+ <!-- billing address -->
+ <div>
+ <div class="uppercase tracking-widest mb-2">
+ <%= Spree.t(:billing_address) %>
+ </div>
+ <div class="!leading-[1.375rem] text-neutral-800">
+ <%= render 'spree/shared/address', address: order.billing_address %>
+ </div>
</div>
- <div class="!leading-[1.375rem] text-neutral-800">
- <%= render collection: order.payments.valid, partial: 'spree/shared/payment', cached: spree_storefront_base_cache_scope %>
+ <% end %>
+ <% if order.payments.valid.any? %>
+ <!-- payment into -->
+ <div class="mb-5 lg:mb-0">
+ <div class="uppercase tracking-widest mb-2">
+ <%= Spree.t(:payment_information) %>
+ </div>
+ <div class="!leading-[1.375rem] text-neutral-800">
+ <%= render collection: order.payments.valid, partial: 'spree/shared/payment', cached: spree_storefront_base_cache_scope %>
+ </div>
</div>
- </div>
+ <% end %>
</div>
<!-- totals/summary -->
<div class="p-4 lg:p-6 text-sm">
diff --git a/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb b/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb
index c58d43bd5d..573334c17b 100644
--- a/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb
+++ b/storefront/app/views/themes/default/spree/shared/_order_shipment.html.erb
@@ -1,14 +1,15 @@
<li class="border border-accent mb-4">
<div class="p-4 lg:p-6">
<div class="flex flex-col lg:flex-row lg:gap-6 gap-4">
- <% if shipment.order.requires_ship_address? %>
+ <% ship_address = shipment.address || shipment.order.ship_address %>
+ <% if shipment.order.requires_ship_address? && ship_address.present? %>
<div class="text-sm lg:w-1/2">
<div class="tracking-widest uppercase mb-2">
<%= Spree.t(:delivery_address) %>
</div>
<div class="!leading-[1.375rem] text-neutral-800">
<%= render "spree/shared/address",
- address: shipment.address || shipment.order.ship_address %>
+ address: ship_address %>
</div>
</div>
<% end %>
diff --git a/storefront/spec/controllers/spree/orders_controller_spec.rb b/storefront/spec/controllers/spree/orders_controller_spec.rb
index 3a5b24eeff..0915fd6ccf 100644
--- a/storefront/spec/controllers/spree/orders_controller_spec.rb
+++ b/storefront/spec/controllers/spree/orders_controller_spec.rb
@@ -120,7 +120,6 @@ describe Spree::OrdersController, type: :controller do
end
end
-
context 'when order does not require ship address' do
let(:digital_shipping_method) { create(:digital_shipping_method) }
let(:digital_product) { create(:product, shipping_category: digital_shipping_method.shipping_categories.first) }
@@ -135,6 +134,16 @@ describe Spree::OrdersController, type: :controller do
end
end
+ context 'when order was free and doesn\'t require billing address' do
+ let(:order) { create(:completed_order_with_totals, store: store, user: user, bill_address: nil) }
+
+ it 'renders the show template' do
+ get :show, params: { id: order.number, token: order.token }
+ expect(response).to render_template(:show)
+ expect(response.body).not_to include(Spree.t(:billing_address))
+ end
+ end
+
context 'when order belongs to another user' do
let(:order) { create(:completed_order_with_totals, store: store, user: create(:user)) }