Don't select a random shipping method in Shipment

This commit is contained in:
Matt-Yorkley
2021-09-01 11:43:06 +01:00
parent 3dd8ed85b4
commit 978c882ed9
2 changed files with 5 additions and 2 deletions

View File

@@ -84,7 +84,9 @@ module Spree
end
def shipping_method
selected_shipping_rate.try(:shipping_method) || shipping_rates.first.try(:shipping_method)
method = selected_shipping_rate.try(:shipping_method)
method ||= shipping_rates.first.try(:shipping_method) unless order.manual_shipping_selection
method
end
def add_shipping_method(shipping_method, selected = false)
@@ -263,7 +265,7 @@ module Spree
fee_adjustment.amount = selected_shipping_rate.cost if fee_adjustment.open?
fee_adjustment.save!
fee_adjustment.reload
elsif selected_shipping_rate_id
elsif shipping_method
shipping_method.create_adjustment(adjustment_label,
self,
true,

View File

@@ -388,6 +388,7 @@ describe Spree::Shipment do
end
it "should create adjustment when not present" do
allow(shipment).to receive_messages(fee_adjustment: nil)
allow(shipment).to receive_messages(selected_shipping_rate_id: 1)
expect(shipping_method).to receive(:create_adjustment).with(shipment.adjustment_label,
shipment, true, "open")