From 3a9b71bd1f70e79d8f5f03f395f787e57ec6c077 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 19 Jul 2017 11:18:20 +0200 Subject: [PATCH] Add doc to methods and classes [skip ci] --- app/controllers/checkout_controller.rb | 3 +++ app/controllers/spree/paypal_controller_decorator.rb | 3 +++ app/services/reset_order_service.rb | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index cfb8b33f45..13d9e71d51 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -60,6 +60,9 @@ class CheckoutController < Spree::CheckoutController end end + # Clears the cached order. Required for #current_order to return a new order + # to serve as cart. See https://github.com/spree/spree/blob/1-3-stable/core/lib/spree/core/controller_helpers/order.rb#L14 + # for details. def expire_current_order session[:order_id] = nil @current_order = nil diff --git a/app/controllers/spree/paypal_controller_decorator.rb b/app/controllers/spree/paypal_controller_decorator.rb index 3c63d2e763..9ad11927ab 100644 --- a/app/controllers/spree/paypal_controller_decorator.rb +++ b/app/controllers/spree/paypal_controller_decorator.rb @@ -7,6 +7,9 @@ Spree::PaypalController.class_eval do redirect_to main_app.checkout_path end + # Clears the cached order. Required for #current_order to return a new order + # to serve as cart. See https://github.com/spree/spree/blob/1-3-stable/core/lib/spree/core/controller_helpers/order.rb#L14 + # for details. def expire_current_order session[:order_id] = nil @current_order = nil diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 18e53272ec..10bd4cd740 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -1,10 +1,18 @@ +# Builds a new order based on the one specified. This implements the "continue +# shopping" feature once an order is completed. class ResetOrderService + + # Constructor + # + # @param controller [#expire_current_order, #current_order] + # @param order [Spree::Order] def initialize(controller, order) @controller = controller @distributor = order.distributor @token = order.token end + # Expires the order currently in use and builds a new one based on it def call controller.expire_current_order build_new_order @@ -14,6 +22,7 @@ class ResetOrderService attr_reader :controller, :distributor, :token + # Builds an order setting the token and distributor of the one specified def build_new_order new_order = controller.current_order(true) new_order.set_distributor!(distributor)