Module: SpreeCmCommissioner::Checkout::UpdateDecorator

Defined in:
app/services/spree_cm_commissioner/checkout/update_decorator.rb

Instance Method Summary collapse

Instance Method Details

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

Override to:

  1. Validate line items are in stock before updating address

  2. Skip automatic state transitions (lines 17-18 commented out) State changes are handled by the advance action, not update



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/spree_cm_commissioner/checkout/update_decorator.rb', line 8

def call(order:, params:, permitted_attributes:, request_env:)
  return failure(order) unless order.ensure_line_items_are_in_stock

  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