6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/services/spree/checkout/advance.rb', line 6
def call(order:, state: nil, shipping_method_id: nil)
return failure(order) if state.present? && !order.has_checkout_step?(state)
return success(order) if state.present? && order.passed_checkout_step?(state)
old_state = order.state
order_updater_ran = false
transitions_count = 0
until cannot_make_transition?(order, state)
next_result = Spree::Dependencies.checkout_next_service.constantize.call(order: order)
return failure(order, order.errors) if next_result.failure? && (transitions_count.zero? || state.present?)
transitions_count +=1
if order.delivery? &&
shipping_method_id.present? &&
order.shipments.count == 1 &&
order.shipping_method.id != shipping_method_id
result = Spree::Checkout::SelectShippingMethod.call(order: order, params: { shipping_method_id: shipping_method_id })
order_updater_ran = result.success?
end
end
if order.state != old_state && !order_updater_ran
order.updater.update_shipment_state
order.updater.update_payment_state
order.save! if order.changed?
end
success(order)
end
|