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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
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.rbindex 7681fee311..ecf481fdf7 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -155,7 +155,7 @@ module Spreebefore_create :create_tokenbefore_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.rbindex 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 Spreeexpect(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+ endendcontext 'when product does not have a price in given currency' do