diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 94d61277ef..98b3530e88 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -28,7 +28,6 @@ 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,12 +50,6 @@ 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 diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 1285ce297c..c5b22b4784 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true module CheckoutHelper + def shipping_and_billing_match?(order) + order.ship_address == order.bill_address + end + def guest_checkout_allowed? current_order.distributor.allow_guest_orders? end diff --git a/app/views/split_checkout/_details.html.haml b/app/views/split_checkout/_details.html.haml index 59504af294..dda5bd70d9 100644 --- a/app/views/split_checkout/_details.html.haml +++ b/app/views/split_checkout/_details.html.haml @@ -102,10 +102,10 @@ = @order.order_cycle.pickup_time_for(@order.distributor) %div.checkout-input{ "data-toggle-target": "content", style: "display: #{display_ship_address ? 'block' : 'none'}" } - = f.check_box :ship_address_same_as_billing, { id: "ship_address_same_as_billing", name: "ship_address_same_as_billing", "data-action": "shippingmethod#showHideShippingAddress", "data-shippingmethod-target": "shippingAddressCheckbox", checked: @ship_address_same_as_billing == "1" }, 1, nil + = f.check_box :ship_address_same_as_billing, { id: "ship_address_same_as_billing", name: "ship_address_same_as_billing", "data-action": "shippingmethod#showHideShippingAddress", "data-shippingmethod-target": "shippingAddressCheckbox", checked: shipping_and_billing_match?(@order) }, 1, nil = f.label :ship_address_same_as_billing, t(:checkout_address_same), { for: "ship_address_same_as_billing" } - %div{"data-shippingmethod-target": "shippingMethodAddress", style: "display: #{display_ship_address == false || @ship_address_same_as_billing == "1" ? 'none' : 'block'}" } + %div{"data-shippingmethod-target": "shippingMethodAddress", style: "display: #{display_ship_address == false || shipping_and_billing_match?(@order) ? 'none' : 'block'}" } = f.fields :ship_address, model: @order.ship_address do |ship_address| %div.checkout-input = ship_address.label :address1, t("split_checkout.step1.address.address1.label")