mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Refactor RestartCheckout service just extracted
This commit is contained in:
@@ -5,11 +5,29 @@ class RestartCheckout
|
||||
end
|
||||
|
||||
def restart_checkout
|
||||
return if @order.state == 'cart'
|
||||
@order.restart_checkout! # resets state to 'cart'
|
||||
@order.update_attributes!(shipping_method_id: nil)
|
||||
@order.shipments.with_state(:pending).destroy_all
|
||||
@order.payments.with_state(:checkout).destroy_all
|
||||
@order.reload
|
||||
return if order.cart?
|
||||
|
||||
reset_state_to_cart
|
||||
clear_shipments
|
||||
clear_payments
|
||||
|
||||
order.reload
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :order
|
||||
|
||||
def reset_state_to_cart
|
||||
order.restart_checkout!
|
||||
end
|
||||
|
||||
def clear_shipments
|
||||
order.update_attributes!(shipping_method_id: nil)
|
||||
order.shipments.with_state(:pending).destroy_all
|
||||
end
|
||||
|
||||
def clear_payments
|
||||
order.payments.with_state(:checkout).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user