diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 804e09de3f..bf83aa35fb 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -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, diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb index 1a18b3777c..f1f13edbb7 100644 --- a/spec/models/spree/shipment_spec.rb +++ b/spec/models/spree/shipment_spec.rb @@ -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")