Extract #shipping_and_billing_match? helper

This commit is contained in:
Matt-Yorkley
2021-09-01 12:06:39 +01:00
parent ac4d721de0
commit 3fabe308cd
3 changed files with 6 additions and 9 deletions

View File

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

View File

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

View File

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