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.

Make sure that after shipment is split, the new shipment has updated cost (#12134)

Damian Kaczmarczykc923ac3ec5f5
diff --git a/core/app/models/spree/fulfilment_changer.rb b/core/app/models/spree/fulfilment_changer.rb
index 46471043e7..8bf2262824 100644
--- a/core/app/models/spree/fulfilment_changer.rb
+++ b/core/app/models/spree/fulfilment_changer.rb
@@ -109,6 +109,7 @@ module Spree
end
desired_shipment.refresh_rates
+ desired_shipment.update_amounts
desired_shipment.order.reload
desired_shipment.order.update_with_updater!
diff --git a/core/spec/models/spree/fulfilment_changer_spec.rb b/core/spec/models/spree/fulfilment_changer_spec.rb
index c5723a3956..68f00c2790 100644
--- a/core/spec/models/spree/fulfilment_changer_spec.rb
+++ b/core/spec/models/spree/fulfilment_changer_spec.rb
@@ -380,6 +380,17 @@ describe Spree::FulfilmentChanger do
expect { subject }.to change { Spree::Shipment.count }.by(1)
end
+ it 'updates desired shipment cost after selecting the shipping rate' do
+ Spree::ShippingMethod.delete_all
+ calculator = Spree::Calculator::Shipping::FlatRate.create!(preferred_amount: 10)
+ shipping_method_that_should_be_selected = create(:shipping_method, calculator: calculator)
+
+ subject
+
+ expect(desired_shipment.reload.shipping_method).to eq(shipping_method_that_should_be_selected)
+ expect(desired_shipment.reload.cost).to eq(10)
+ end
+
context 'if the desired shipment is invalid' do
let(:desired_shipment) { order.shipments.build(stock_location_id: 99_999_999) }