From 08fb496f55873acaf52b6f854570171c68ca49d8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 14 Feb 2023 09:46:29 +0100 Subject: [PATCH] Don't need to show any ship_address errors if no ship selected nor if the ship_address is the same than the billing one --- app/controllers/split_checkout_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 997ef5e5bf..752cec3010 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -59,12 +59,17 @@ class SplitCheckoutController < ::BaseController def order_error_messages # Remove ship_address.* errors if no shipping method is not selected - remove_ship_address_errors if @order.errors[:shipping_method].present? + remove_ship_address_errors if no_ship_address_needed? + # Reorder errors to make sure the most important ones are shown first # and finally, return the error messages to sentence reorder_errors.map(&:full_message).to_sentence end + def no_ship_address_needed? + @order.errors[:shipping_method].present? || params[:ship_address_same_as_billing] == "1" + end + def remove_ship_address_errors @order.errors.delete("ship_address.firstname") @order.errors.delete("ship_address.address1")