From bee1b1a097ae6aad3d42748509a2f4f60f01cf9d Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Wed, 25 Aug 2021 15:22:25 -0700 Subject: [PATCH] respect checkbox for ship address same as bill address --- app/controllers/split_checkout_controller.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 80a00b2b62..a26978b3e3 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -28,6 +28,7 @@ class SplitCheckoutController < ::BaseController @order.errors.clear @order.bill_address.errors.clear @order.ship_address.errors.clear + @ship_address_same_as_billing = "1" if ship_address_matches_bill_address? rescue Spree::Core::GatewayError => e rescue_from_spree_gateway_error(e) end @@ -51,6 +52,12 @@ class SplitCheckoutController < ::BaseController private + def ship_address_matches_bill_address? + attrs_to_check = %w(firstname lastname address1 address2 state_id city zipcode phone country_id) + ((@order.bill_address.attributes.to_a - + @order.ship_address.attributes.to_a).map(&:first) & attrs_to_check).blank? + end + def handle_shipping_method_selection return unless @shipping_method @@ -65,14 +72,17 @@ class SplitCheckoutController < ::BaseController @shipping_method = @order.shipping_method @shipping_method_id = @shipping_method&.id end - - @ship_address_same_as_billing = params.dig(:order, "Checkout.ship_address_same_as_billing") end def populate_ship_address_params return unless params.dig(:order, :ship_address_attributes).present? && params.dig(:order, :bill_address_attributes).present? + if params.dig(:order, "Checkout.ship_address_same_as_billing") == "1" + params[:order][:ship_address_attributes] = params[:order][:bill_address_attributes] + return + end + address_attrs = [ :firstname, :lastname,