Spree::Order.class_eval do # Make sure the order confirmation is delivered when the order has been paid for. def finalize! # lock all adjustments (coupon promotions, etc.) all_adjustments.each(&:close) # update payment and shipment(s) states, and save updater.update_payment_state shipments.each do |shipment| shipment.update!(self) shipment.finalize! if paid? end updater.update_shipment_state save! updater.run_hooks touch :completed_at deliver_order_confirmation_email unless confirmation_delivered? or !paid? consider_risk end end