mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Fix bug when in specific scenario user couldn't proceed to payment step
When using a "pick up" shipping method, with a user who doesn't have a shipping address it was impossible to proceed to the payment step because shipping address was invalid. To fix this, we ensure that "ship_address_same_as_billing" parameter is set to true when using a "pick up" shipping method. use distributor address when shipping method doesn't require a ship address ; in doing this we follow the same logic as the legacy checkout
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
2814b1f399
commit
23c4298519
@@ -141,6 +141,10 @@ 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.updater.update_totals_and_states
|
||||
@@ -150,6 +154,29 @@ class SplitCheckoutController < ::BaseController
|
||||
@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 = allowed_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 summary_step?
|
||||
params[:step] == "summary"
|
||||
end
|
||||
|
||||
@@ -458,6 +458,19 @@ describe "As a consumer, I want to checkout my order" do
|
||||
fill_notes("SpEcIaL NoTeS")
|
||||
proceed_to_payment
|
||||
end
|
||||
|
||||
context 'when the user has no shipping address' do
|
||||
before do
|
||||
# Hack so we can have "Shipping address same as billing address?" unticked
|
||||
choose free_shipping_with_required_address.name
|
||||
uncheck "Shipping address same as billing address?"
|
||||
choose free_shipping_without_required_address.name
|
||||
end
|
||||
|
||||
it "redirects the user to the Payment Method step" do
|
||||
proceed_to_payment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "selecting a delivery method with a shipping fee" do
|
||||
|
||||
Reference in New Issue
Block a user