Merge pull request #10496 from rioug/10479-split-checkout-fix-user-blocked-at-step1

[split checkout] Fix bug preventing user from reaching payment step
This commit is contained in:
Rachel Arnould
2023-03-08 15:44:50 +01:00
committed by GitHub
2 changed files with 40 additions and 0 deletions

View File

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

View File

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