Remove dead code and clarify update logic

This commit is contained in:
Matt-Yorkley
2023-06-06 15:23:38 +01:00
parent e88843c733
commit c7bb24e2a0
2 changed files with 10 additions and 13 deletions

View File

@@ -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

View File

@@ -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