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.

Drop the legacy admin shipment branch from cart recalculation

Damian Legawiecfebc5981ff6b
diff --git a/spree/core/app/services/spree/carts/recalculate.rb b/spree/core/app/services/spree/carts/recalculate.rb
index 6d684f83da..0974f05744 100644
--- a/spree/core/app/services/spree/carts/recalculate.rb
+++ b/spree/core/app/services/spree/carts/recalculate.rb
@@ -8,21 +8,13 @@ module Spree
order.remove_gift_card if order.gift_card.present?
order.payments.store_credits.checkout.destroy_all if order.payments.store_credits.checkout.any?
+ # Totals must be current before the proposal rebuild — delivery rate
+ # calculators (e.g. price sack) read them.
order_updater.update_item_count
order_updater.update_totals
order_updater.persist_totals
- shipment = options[:shipment]
- if shipment.present?
- # ADMIN END SHIPMENT RATE FIX
- # refresh shipments to ensure correct shipment amount is calculated when using price sack calculator
- # for calculating shipment rates.
- # Currently shipment rate is calculated on previous order total instead of current order total when updating a shipment from admin end.
- order.refresh_shipment_rates(::Spree::DeliveryMethod::DISPLAY_ON_BACK_END)
- shipment.update_amounts
- else
- order.ensure_updated_shipments
- end
+ order.ensure_updated_shipments
::Spree::PromotionHandler::Cart.new(order, line_item).activate
# Typed rows (discounts + tax) are rebuilt by the order-level
diff --git a/spree/core/spec/services/spree/carts/legacy_add_item_spec.rb b/spree/core/spec/services/spree/carts/legacy_add_item_spec.rb
index e7e8516613..52d22d86a7 100644
--- a/spree/core/spec/services/spree/carts/legacy_add_item_spec.rb
+++ b/spree/core/spec/services/spree/carts/legacy_add_item_spec.rb
@@ -31,19 +31,6 @@ module Spree
end
end
- context 'with given shipment' do
- let(:shipment) { create :shipment }
- let(:options) { { shipment: shipment } }
- let(:execute) { subject.call(order: order, variant: variant, quantity: qty, options: options) }
-
- it 'ensure shipment calls update_amounts instead of order calling ensure_updated_shipments' do
- expect(order).to receive(:refresh_shipment_rates).with(Spree::ShippingMethod::DISPLAY_ON_BACK_END)
- expect(order).not_to receive(:ensure_updated_shipments)
- expect(shipment).to receive(:update_amounts)
- expect(execute).to be_success
- end
- end
-
context 'not given a shipment' do
let(:execute) { subject.call(order: order, variant: variant, quantity: qty) }
diff --git a/spree/core/spec/services/spree/carts/legacy_remove_item_spec.rb b/spree/core/spec/services/spree/carts/legacy_remove_item_spec.rb
index 4dde65eba2..c873a069ba 100644
--- a/spree/core/spec/services/spree/carts/legacy_remove_item_spec.rb
+++ b/spree/core/spec/services/spree/carts/legacy_remove_item_spec.rb
@@ -43,18 +43,6 @@ module Spree
end
end
- context 'given a shipment' do
- let(:shipment) { create :shipment }
- let(:options) { { shipment: shipment } }
- let(:execute) { subject.call order: order, variant: variant, options: options }
-
- it 'ensure shipment calls update_amounts instead of order calling ensure_updated_shipments' do
- expect(order).not_to receive(:ensure_updated_shipments)
- expect(shipment).to receive(:update_amounts)
- expect(execute).to be_success
- end
- end
-
context 'not given a shipment' do
let(:execute) { subject.call order: order, variant: variant }
diff --git a/spree/core/spec/services/spree/carts/legacy_remove_line_item_spec.rb b/spree/core/spec/services/spree/carts/legacy_remove_line_item_spec.rb
index ea51af1eac..30e9c2b52e 100644
--- a/spree/core/spec/services/spree/carts/legacy_remove_line_item_spec.rb
+++ b/spree/core/spec/services/spree/carts/legacy_remove_line_item_spec.rb
@@ -36,18 +36,6 @@ module Spree
end
end
- context 'given a shipment' do
- let(:shipment) { create :shipment }
- let(:options) { { shipment: shipment } }
- let(:execute) { subject.call order: order, line_item: line_item, options: options }
-
- it 'ensure shipment calls update_amounts instead of order calling ensure_updated_shipments' do
- expect(order).not_to receive(:ensure_updated_shipments)
- expect(shipment).to receive(:update_amounts)
- expect(execute).to be_success
- end
- end
-
context 'not given a shipment' do
let(:execute) { subject.call order: order, line_item: line_item }
diff --git a/spree/core/spec/services/spree/line_items/destroy_spec.rb b/spree/core/spec/services/spree/line_items/destroy_spec.rb
index 0c7341323e..1fc07e145b 100644
--- a/spree/core/spec/services/spree/line_items/destroy_spec.rb
+++ b/spree/core/spec/services/spree/line_items/destroy_spec.rb
@@ -21,18 +21,6 @@ module Spree
end
end
- context 'given a shipment' do
- let(:shipment) { create :shipment }
- let(:options) { { shipment: shipment } }
- let(:execute) { subject.call(line_item: line_item, options: options) }
-
- it 'ensure shipment calls update_amounts instead of order calling ensure_updated_shipments' do
- expect(order).not_to receive(:ensure_updated_shipments)
- expect(shipment).to receive(:update_amounts)
- expect(execute).to be_success
- end
- end
-
context 'not given a shipment' do
let(:execute) { subject.call(line_item: line_item) }
diff --git a/spree/core/spec/services/spree/line_items/update_spec.rb b/spree/core/spec/services/spree/line_items/update_spec.rb
index aa276640f4..1260982e94 100644
--- a/spree/core/spec/services/spree/line_items/update_spec.rb
+++ b/spree/core/spec/services/spree/line_items/update_spec.rb
@@ -22,18 +22,6 @@ module Spree
end
end
- context 'given a shipment' do
- let(:shipment) { create :shipment }
- let(:options) { { shipment: shipment } }
- let(:execute) { subject.call(line_item: line_item, line_item_attributes: line_item_attributes, options: options) }
-
- it 'ensure shipment calls update_amounts instead of order calling ensure_updated_shipments' do
- expect(order).not_to receive(:ensure_updated_shipments)
- expect(shipment).to receive(:update_amounts)
- expect(execute).to be_success
- end
- end
-
context 'not given a shipment' do
let(:execute) { subject.call(line_item: line_item, line_item_attributes: line_item_attributes) }