From 978c882ed96dd8ca269a60af4c53c27de5688e39 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 1 Sep 2021 11:43:06 +0100 Subject: [PATCH] Don't select a random shipping method in Shipment --- app/models/spree/shipment.rb | 6 ++++-- spec/models/spree/shipment_spec.rb | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) 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")