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
This commit is contained in:
Jean-Baptiste Bellet
2023-02-14 09:46:29 +01:00
parent 4cea7b1957
commit 08fb496f55

View File

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