From c7bb24e2a025fee1e5ab41c6b7145389374ca84d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 6 Jun 2023 15:23:38 +0100 Subject: [PATCH] Remove dead code and clarify update logic --- .../spree/admin/orders_controller.rb | 18 +++++++++--------- app/views/spree/admin/orders/edit.html.haml | 5 +---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 0e5cb4b825..9e141d7674 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -44,16 +44,9 @@ module Spree def update on_update - if params[:set_distribution_step] && @order.update(order_params) - OrderWorkflow.new(@order).advance_to_payment if @order.state.in? ["cart", "address", "delivery"] - return redirect_to spree.admin_order_customer_path(@order) - end - - unless order_params.present? && @order.update(order_params) && @order.line_items.present? - if @order.line_items.empty? && !params[:suppress_error_msg] - @order.errors.add(:line_items, Spree.t('errors.messages.blank')) - end + order_updated = order_params.present? && @order.update(order_params) + unless order_updated && line_items_present? flash[:error] = @order.errors.full_messages.join(', ') if @order.errors.present? return redirect_to spree.edit_admin_order_path(@order) end @@ -111,6 +104,13 @@ module Spree private + def line_items_present? + return true if @order.line_items.any? + + @order.errors.add(:line_items, Spree.t('errors.messages.blank')) + false + end + def update_search_results session[:admin_orders_search] = search_params diff --git a/app/views/spree/admin/orders/edit.html.haml b/app/views/spree/admin/orders/edit.html.haml index 6a88c85ebd..6e290d3502 100644 --- a/app/views/spree/admin/orders/edit.html.haml +++ b/app/views/spree/admin/orders/edit.html.haml @@ -16,10 +16,7 @@ = render partial: "spree/admin/shared/order_tabs", locals: { current: 'Order Details' } %div - -# Suppress errors when manually creating a new order - needs to proceed to edit page - -# without having line items (which otherwise gives a validation error) - - unless params["suppress_error_msg"] - = render partial: "spree/shared/error_messages", :locals => { :target => @order } + = render partial: "spree/shared/error_messages", locals: { target: @order } = admin_inject_shops(module: 'admin.orders') = admin_inject_order_cycles