From fabca8400144338c5c6d5232178ceb69d83c487f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 29 Mar 2019 17:11:05 +1100 Subject: [PATCH] Close adjustments so that updates are effective Spree 2.0 keeps shipping fee adjustments open unless they are manually closed. But open adjustments cannot be edited. To preserve updates, like changing the amount of the shipping fee we close the adjustment first. --- .../spree/admin/adjustments_controller_decorator.rb | 13 ++++++++++++- spec/features/admin/orders_spec.rb | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/adjustments_controller_decorator.rb b/app/controllers/spree/admin/adjustments_controller_decorator.rb index f822709e15..a45e3b4859 100644 --- a/app/controllers/spree/admin/adjustments_controller_decorator.rb +++ b/app/controllers/spree/admin/adjustments_controller_decorator.rb @@ -3,7 +3,7 @@ module Spree AdjustmentsController.class_eval do prepend_before_filter :set_included_tax, only: [:create, :update] before_filter :set_default_tax_rate, only: :edit - + before_filter :enable_updates, only: :update private @@ -38,6 +38,17 @@ module Spree params[:adjustment][:included_tax] = 0 end end + + # Spree 2.0 keeps shipping fee adjustments open unless they are manually + # closed. But open adjustments cannot be edited. + # To preserve updates, like changing the amount of the shipping fee, + # we close the adjustment first. + # + # The Spree admin interface allows to open and close adjustments manually + # but we removed that functionality as it had no purpose for us. + def enable_updates + @adjustment.close + end end end end diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index 48072ddad8..f366b1db4d 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -350,6 +350,16 @@ feature %q{ end end end + + scenario "editing shipping fees" do + click_link "Adjustments" + page.find('td.actions a.icon-edit').click + + fill_in "Amount", with: "5" + click_button "Continue" + + expect(page.find("td.amount")).to have_content "$5.00" + end end scenario "creating an order with distributor and order cycle" do