Class: Spree::OrdersController
- Inherits:
-
StoreController
- Object
- BaseController
- StoreController
- Spree::OrdersController
- Defined in:
- app/controllers/spree/orders_controller.rb
Instance Method Summary collapse
- #accurate_title ⇒ Object
- #check_authorization ⇒ Object
-
#edit ⇒ Object
Shows the current incomplete order from the session.
- #empty ⇒ Object
-
#populate ⇒ Object
Adds a new item to the order (creating a new order if none already exists).
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from StoreController
Instance Method Details
#accurate_title ⇒ Object
75 76 77 |
# File 'app/controllers/spree/orders_controller.rb', line 75 def accurate_title @order && @order.completed? ? "#{Spree.t(:order)} #{@order.number}" : Spree.t(:shopping_cart) end |
#check_authorization ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/spree/orders_controller.rb', line 79 def session[:access_token] ||= params[:token] order = Spree::Order.find_by_number(params[:id]) || current_order if order :edit, order, session[:access_token] else :create, Spree::Order end end |
#edit ⇒ Object
Shows the current incomplete order from the session
45 46 47 48 |
# File 'app/controllers/spree/orders_controller.rb', line 45 def edit @order = current_order(true) associate_user end |
#empty ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/controllers/spree/orders_controller.rb', line 67 def empty if @order = current_order @order.empty! end redirect_to spree.cart_path end |
#populate ⇒ Object
Adds a new item to the order (creating a new order if none already exists)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/spree/orders_controller.rb', line 51 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..join(" ") redirect_to :back end end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/spree/orders_controller.rb', line 11 def show @order = Order.find_by_number!(params[:id]) end |
#update ⇒ Object
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 |
# File 'app/controllers/spree/orders_controller.rb', line 15 def update @order = current_order unless @order flash[:error] = Spree.t(:order_not_found) redirect_to root_path and return end if @order.update_attributes(params[:order]) @order.line_items = @order.line_items.select {|li| li.quantity > 0 } @order.create_proposed_shipments if @order.shipments.any? return if after_update_attributes fire_event('spree.order.contents_changed') respond_with(@order) do |format| format.html do if params.has_key?(:checkout) @order.next_transition.run_callbacks if @order.cart? redirect_to checkout_state_path(@order.checkout_steps.first) else redirect_to cart_path end end end else respond_with(@order) end end |