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
# 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
  order.state = 'address' if (ship_changed || bill_changed) && order.has_checkout_step?('address')
  order.state = 'delivery' if selected_shipping_rate_present?(params) && order.has_checkout_step?('delivery')
  return success(order) if order.update_from_params(params, permitted_attributes, request_env)

  failure(order)
end