mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract #shipping_and_billing_match? helper
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user