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.

Reset shipments and checkout flow after changing currency (#11698)

Karol Szuster960c9303b2d5
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 7681fee311..ecf481fdf7 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -155,7 +155,7 @@ module Spree
before_create :create_token
before_create :link_by_email
- before_update :homogenize_line_item_currencies, if: :currency_changed?
+ before_update :ensure_updated_shipments, :homogenize_line_item_currencies, if: :currency_changed?
with_options presence: true do
# we want to have this case_sentive: true as changing it to false causes all SQL to use LOWER(slug)
diff --git a/core/spec/services/spree/cart/change_currency_spec.rb b/core/spec/services/spree/cart/change_currency_spec.rb
index 57e920479b..3c8fd65169 100644
--- a/core/spec/services/spree/cart/change_currency_spec.rb
+++ b/core/spec/services/spree/cart/change_currency_spec.rb
@@ -19,6 +19,23 @@ module Spree
expect(order.currency).to eq('EUR')
expect(order.line_items.first.currency).to eq('EUR')
end
+
+ it 'removes the shipment and restarts the checkout flow' do
+ expect(subject).to be_success
+ order.reload
+ expect(order.shipments).to be_empty
+ expect(order.state).to eq('address')
+ end
+
+ context 'when the order has no shipment' do
+ let(:order) { create(:order_with_totals, store: store, currency: 'USD', state: 'delivery') }
+
+ it 'does not restart the checkout flow' do
+ expect(subject).to be_success
+ order.reload
+ expect(order.state).to eq('delivery')
+ end
+ end
end
context 'when product does not have a price in given currency' do