mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Move address params handling into Checkout::Params
This commit is contained in:
committed by
Maikel Linke
parent
13a7c19a06
commit
dd9bdd9c0e
@@ -94,10 +94,6 @@ class SplitCheckoutController < ::BaseController
|
||||
def update_order
|
||||
return if params[:confirm_order] || @order.errors.any?
|
||||
|
||||
# If we have "pick up" shipping method (require_ship_address is set to false), use the
|
||||
# distributor address as shipping address
|
||||
use_shipping_address_from_distributor if shipping_method_ship_address_not_required?
|
||||
|
||||
@order.select_shipping_method(params[:shipping_method_id])
|
||||
@order.update(order_params)
|
||||
@order.update_totals_and_states
|
||||
@@ -109,29 +105,6 @@ class SplitCheckoutController < ::BaseController
|
||||
Checkout::Validation.new(@order, params).call && @order.errors.empty?
|
||||
end
|
||||
|
||||
def use_shipping_address_from_distributor
|
||||
@order.ship_address = @order.address_from_distributor
|
||||
|
||||
# Add the missing data
|
||||
bill_address = params[:order][:bill_address_attributes]
|
||||
@order.ship_address.firstname = bill_address[:firstname]
|
||||
@order.ship_address.lastname = bill_address[:lastname]
|
||||
@order.ship_address.phone = bill_address[:phone]
|
||||
|
||||
# Remove shipping address from parameter so we don't override the address we just set
|
||||
params[:order].delete(:ship_address_attributes)
|
||||
end
|
||||
|
||||
def shipping_method_ship_address_not_required?
|
||||
selected_shipping_method = available_shipping_methods&.select do |sm|
|
||||
sm.id.to_s == params[:shipping_method_id]
|
||||
end
|
||||
|
||||
return false if selected_shipping_method.empty?
|
||||
|
||||
selected_shipping_method.first.require_ship_address == false
|
||||
end
|
||||
|
||||
def advance_order_state
|
||||
return if @order.complete?
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ module Checkout
|
||||
return {} unless params[:order]
|
||||
|
||||
apply_strong_parameters
|
||||
set_pickup_address
|
||||
set_address_details
|
||||
set_payment_amount
|
||||
set_existing_card
|
||||
@@ -36,6 +37,17 @@ module Checkout
|
||||
)
|
||||
end
|
||||
|
||||
def set_pickup_address
|
||||
return unless shipping_method && !shipping_method.require_ship_address?
|
||||
|
||||
order.ship_address = order.distributor.address.clone
|
||||
order.ship_address.firstname = @order_params[:bill_address_attributes][:firstname]
|
||||
order.ship_address.lastname = @order_params[:bill_address_attributes][:lastname]
|
||||
order.ship_address.phone = @order_params[:bill_address_attributes][:phone]
|
||||
|
||||
@order_params.delete(:ship_address_attributes)
|
||||
end
|
||||
|
||||
def set_address_details
|
||||
return unless addresses_present?
|
||||
|
||||
@@ -64,6 +76,12 @@ module Checkout
|
||||
@order_params[:payments_attributes].first[:source] = card
|
||||
end
|
||||
|
||||
def shipping_method
|
||||
return unless params[:shipping_method_id]
|
||||
|
||||
@shipping_method ||= Spree::ShippingMethod.find(params[:shipping_method_id])
|
||||
end
|
||||
|
||||
def existing_card_selected?
|
||||
@order_params[:payments_attributes] && params[:existing_card_id].present?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user