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.

Added deprecation bridges for checkout steps on Order

Damian Legawiecf766a6f81f6d
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rb
index d2ddba041a..10d72364ca 100644
--- a/spree/core/app/models/spree/order.rb
+++ b/spree/core/app/models/spree/order.rb
@@ -92,6 +92,54 @@ module Spree
order
end
+ # Checkout-step introspection belongs to Spree::Cart
+ # ({Spree::Purchase::CheckoutSteps}) since 6.0 — an order is past checkout
+ # by definition. These bridges answer for an upgrader reaching for the
+ # Spree 5 API on an order, rather than raising NoMethodError.
+ #
+ # The step list is data-driven, so it stays accurate here: the registry
+ # computes it from the record's own predicates, all of which Order carries.
+ # Where the checkout stands within that list is not, which is why the
+ # readers below report a finished checkout.
+
+ # @deprecated Checkout steps belong to Spree::Cart; removed in 6.1.
+ def checkout_steps
+ Spree::Deprecation.warn('Spree::Order#checkout_steps is deprecated and will be removed in Spree 6.1. Checkout steps belong to Spree::Cart — ask the cart before it is completed.')
+ Spree::Checkout::Registry.step_names_for(self)
+ end
+
+ # @deprecated See {#checkout_steps}; removed in 6.1.
+ def has_checkout_step?(step)
+ Spree::Deprecation.warn('Spree::Order#has_checkout_step? is deprecated and will be removed in Spree 6.1. Checkout steps belong to Spree::Cart — ask the cart before it is completed.')
+ step.present? && Spree::Checkout::Registry.step_names_for(self).include?(step.to_s)
+ end
+
+ # @deprecated See {#checkout_steps}; removed in 6.1.
+ def checkout_step_index(step)
+ Spree::Deprecation.warn('Spree::Order#checkout_step_index is deprecated and will be removed in Spree 6.1. Checkout steps belong to Spree::Cart — ask the cart before it is completed.')
+ Spree::Checkout::Registry.step_names_for(self).index(step).to_i
+ end
+
+ # @deprecated See {#checkout_steps}; removed in 6.1. An order has no
+ # outstanding step, so this is always 'complete'.
+ def current_checkout_step
+ Spree::Deprecation.warn("Spree::Order#current_checkout_step is deprecated and will be removed in Spree 6.1. An order is past checkout, so this is always 'complete'.")
+ 'complete'
+ end
+
+ # @deprecated See {#checkout_steps}; removed in 6.1.
+ def final_checkout_step
+ Spree::Deprecation.warn('Spree::Order#final_checkout_step is deprecated and will be removed in Spree 6.1. Checkout steps belong to Spree::Cart — ask the cart before it is completed.')
+ Spree::Checkout::Registry.step_names_for(self).reject { |step| step == 'complete' }.last || 'address'
+ end
+
+ # @deprecated See {#checkout_steps}; removed in 6.1. Every step is behind
+ # an order, so this is the whole list bar 'complete'.
+ def completed_checkout_steps
+ Spree::Deprecation.warn("Spree::Order#completed_checkout_steps is deprecated and will be removed in Spree 6.1. An order is past checkout, so every step bar 'complete' is behind it.")
+ Spree::Checkout::Registry.step_names_for(self).reject { |step| step == 'complete' }
+ end
+
# Standardized column names (renamed in 6.0); legacy readers stay as
# aliases one release.
alias_attribute :promo_total, :discount_total
diff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rb
index 21b5aea3a8..e318490a5d 100644
--- a/spree/core/spec/models/spree/order_spec.rb
+++ b/spree/core/spec/models/spree/order_spec.rb
@@ -1825,6 +1825,70 @@ describe Spree::Order, type: :model do
end
end
+ describe 'legacy checkout-step bridges' do
+ # Checkout steps moved to Spree::Cart in 6.0. These warn instead of
+ # raising NoMethodError, and report a checkout that is already finished.
+ let(:order) { create(:completed_order_with_totals) }
+
+ it 'reports the applicable steps from #checkout_steps with a deprecation warning' do
+ expect(Spree::Deprecation).to receive(:warn).with(/checkout_steps is deprecated/)
+
+ expect(order.checkout_steps).to eq(%w[address delivery payment complete])
+ end
+
+ it "reports 'complete' from #current_checkout_step with a deprecation warning" do
+ expect(Spree::Deprecation).to receive(:warn).with(/current_checkout_step/)
+
+ expect(order.current_checkout_step).to eq('complete')
+ end
+
+ it "excludes 'complete' from #final_checkout_step with a deprecation warning" do
+ expect(Spree::Deprecation).to receive(:warn).with(/final_checkout_step/)
+
+ expect(order.final_checkout_step).to eq('payment')
+ end
+
+ it "treats every step bar 'complete' as done in #completed_checkout_steps with a deprecation warning" do
+ expect(Spree::Deprecation).to receive(:warn).with(/completed_checkout_steps/)
+
+ expect(order.completed_checkout_steps).to eq(%w[address delivery payment])
+ end
+
+ describe '#has_checkout_step?' do
+ it 'answers for an applicable step with a deprecation warning' do
+ expect(Spree::Deprecation).to receive(:warn).with(/has_checkout_step\?/)
+
+ expect(order.has_checkout_step?('payment')).to be(true)
+ end
+
+ it 'answers false for a step this order never had' do
+ expect(Spree::Deprecation).to receive(:warn).with(/has_checkout_step\?/)
+
+ expect(order.has_checkout_step?('confirm')).to be(false)
+ end
+
+ it 'answers false for a blank step' do
+ expect(Spree::Deprecation).to receive(:warn).with(/has_checkout_step\?/)
+
+ expect(order.has_checkout_step?(nil)).to be(false)
+ end
+ end
+
+ describe '#checkout_step_index' do
+ it 'reports the position with a deprecation warning' do
+ expect(Spree::Deprecation).to receive(:warn).with(/checkout_step_index/)
+
+ expect(order.checkout_step_index('delivery')).to eq(1)
+ end
+
+ it 'reports 0 for an unknown step, as the cart does' do
+ expect(Spree::Deprecation).to receive(:warn).with(/checkout_step_index/)
+
+ expect(order.checkout_step_index('nope')).to eq(0)
+ end
+ end
+ end
+
describe 'legacy proposal-rebuild bridges' do
it 'delegates #create_proposed_fulfillments to #rebuild_fulfillments! with a deprecation warning' do
order = create(:order)