diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index d303245197..dcab812254 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -175,10 +175,6 @@ class CheckoutController < Spree::CheckoutController end end - def skip_state_validation? - true - end - def load_order @order = current_order redirect_to(main_app.shop_path) && return unless @order && @order.checkout_allowed? diff --git a/app/controllers/spree/checkout_controller.rb b/app/controllers/spree/checkout_controller.rb index df60b86d5e..b802650673 100644 --- a/app/controllers/spree/checkout_controller.rb +++ b/app/controllers/spree/checkout_controller.rb @@ -15,7 +15,6 @@ class Spree::CheckoutController < Spree::StoreController before_filter :ensure_order_not_completed before_filter :ensure_checkout_allowed before_filter :ensure_sufficient_stock_lines - before_filter :ensure_valid_state before_filter :associate_user before_filter :check_authorization @@ -31,56 +30,17 @@ class Spree::CheckoutController < Spree::StoreController redirect_to main_app.checkout_path end + private + #################################### #### Copied from Spree Frontend #### #################################### - # Updates the order and advances to the next state (when possible.) - def update - if @order.update_attributes(object_params) - fire_event('spree.checkout.update') - - unless @order.next - flash[:error] = @order.errors[:base].join("\n") - redirect_to checkout_state_path(@order.state) and return - end - - if @order.completed? - session[:order_id] = nil - flash.notice = Spree.t(:order_processed_successfully) - flash[:commerce_tracking] = "nothing special" - redirect_to completion_route - else - redirect_to checkout_state_path(@order.state) - end - else - render :edit - end - end - - private - - def ensure_valid_state - unless skip_state_validation? - if (params[:state] && !@order.has_checkout_step?(params[:state])) || - (!params[:state] && !@order.has_checkout_step?(@order.state)) - @order.state = 'cart' - redirect_to checkout_state_path(@order.checkout_steps.first) - end - end - end - - # Should be overriden if you have areas of your checkout that don't match - # up to a step within checkout_steps, such as a registration step - def skip_state_validation? - false - end - def load_order @order = current_order redirect_to spree.cart_path and return unless @order if params[:state] - redirect_to checkout_state_path(@order.state) if @order.can_go_to_state?(params[:state]) && !skip_state_validation? + redirect_to checkout_state_path(@order.state) if @order.can_go_to_state?(params[:state]) @order.state = params[:state] end setup_for_current_state @@ -108,27 +68,6 @@ class Spree::CheckoutController < Spree::StoreController spree.order_path(@order) end - # For payment step, filter order parameters to produce the expected nested - # attributes for a single payment and its source, discarding attributes - # for payment methods other than the one selected - def object_params - # respond_to check is necessary due to issue described in #2910 - if @order.has_checkout_step?("payment") && @order.payment? - if params[:payment_source].present? - source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore] - - if source_params - params[:order][:payments_attributes].first[:source_attributes] = source_params - end - end - - if (params[:order][:payments_attributes]) - params[:order][:payments_attributes].first[:amount] = @order.total - end - end - params[:order] - end - def setup_for_current_state method_name = :"before_#{@order.state}" send(method_name) if respond_to?(method_name, true) diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index d393bca6fd..deebcbd81b 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -32,23 +32,6 @@ class Spree::OrdersController < Spree::StoreController @order = Spree::Order.find_by_number!(params[:id]) end - # Adds a new item to the order (creating a new order if none already exists) - def populate - populator = Spree::OrderPopulator.new(current_order(true), current_currency) - if populator.populate(params.slice(:products, :variants, :quantity)) - current_order.create_proposed_shipments if current_order.shipments.any? - - fire_event('spree.cart.add') - fire_event('spree.order.contents_changed') - respond_with(@order) do |format| - format.html { redirect_to cart_path } - end - else - flash[:error] = populator.errors.full_messages.join(" ") - redirect_to :back - end - end - def empty if @order = current_order @order.empty! diff --git a/config/routes/spree.rb b/config/routes/spree.rb index d5e7fec42c..f20e4a204a 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -97,24 +97,9 @@ Spree::Core::Engine.routes.prepend do # non-restful checkout stuff put '/checkout/update/:state', :to => 'checkout#update', :as => :update_checkout get '/checkout/:state', :to => 'checkout#edit', :as => :checkout_state - get '/checkout', :to => 'checkout#edit' , :as => :checkout - populate_redirect = redirect do |params, request| - request.flash[:error] = Spree.t(:populate_get_error) - request.referer || '/cart' - end - - get '/orders/populate', :via => :get, :to => populate_redirect match '/orders/:id/token/:token' => 'orders#show', :via => :get, :as => :token_order - resources :orders do - post :populate, :on => :collection - end - - get '/cart', :to => 'orders#edit', :as => :cart - put '/cart', :to => 'orders#update', :as => :update_cart - put '/cart/empty', :to => 'orders#empty', :as => :empty_cart - # route globbing for pretty nested taxon and product paths match '/t/*id', :to => 'taxons#show', :as => :nested_taxons