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.

Order shipment state should be marked as `partial` when some of the s… (#12258)

Damian Legawiecb6fe46e35e35
diff --git a/core/app/models/spree/order_updater.rb b/core/app/models/spree/order_updater.rb
index 27f18cde75..0de95e1d28 100644
--- a/core/app/models/spree/order_updater.rb
+++ b/core/app/models/spree/order_updater.rb
@@ -133,10 +133,16 @@ module Spree
order.shipment_state = 'backorder'
else
# get all the shipment states for this order
- shipment_states = shipments.states
+ shipment_states = shipments.states.uniq
+
order.shipment_state = if shipment_states.size > 1
- # multiple shipment states means it's most likely partially shipped
- 'partial'
+ if shipment_states.include?('shipped')
+ 'partial'
+ elsif shipment_states.include?('pending')
+ 'pending'
+ else
+ 'ready'
+ end
else
# will return nil if no shipments are found
shipment_states.first
diff --git a/core/spec/models/spree/order_updater_spec.rb b/core/spec/models/spree/order_updater_spec.rb
index 1af3e51691..862e03e930 100644
--- a/core/spec/models/spree/order_updater_spec.rb
+++ b/core/spec/models/spree/order_updater_spec.rb
@@ -105,7 +105,7 @@ module Spree
end
it 'is partial' do
- allow(order).to receive_message_chain(:shipments, :states).and_return(['pending', 'ready'])
+ allow(order).to receive_message_chain(:shipments, :states).and_return(['pending', 'shipped'])
updater.update_shipment_state
expect(order.shipment_state).to eq('partial')
end