Class: Spree::Checkout::Update

Inherits:
Object
  • Object
show all
Includes:
Addresses::Helper, ServiceModule::Base
Defined in:
app/services/spree/checkout/update.rb

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(order:, params:, permitted_attributes:, request_env:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/spree/checkout/update.rb', line 7

def call(order:, params:, permitted_attributes:, request_env:)
  ship_changed = address_with_country_iso_present?(params, 'ship')
  bill_changed = address_with_country_iso_present?(params, 'bill')
  params[:order][:ship_address_attributes] = replace_country_iso_with_id(params[:order][:ship_address_attributes]) if ship_changed
  params[:order][:bill_address_attributes] = replace_country_iso_with_id(params[:order][:bill_address_attributes]) if bill_changed

  # for quick checkouts we cannot revert to previous states
  # we already have the address and delivery steps completed
  # however we need to update the shipping address with missing data
  # as previously we didn't have access to first/last name and street
  unless params[:do_not_change_state]
    order.state = 'address' if (ship_changed || bill_changed || quick_checkout_cancelled?(params)) && order.has_checkout_step?('address')
    order.state = 'delivery' if selected_shipping_rate_present?(params) && order.has_checkout_step?('delivery')
  end

  return success(order) if order.update_from_params(params, permitted_attributes, request_env)

  failure(order)
end