Class: OrdersController
- Inherits:
-
Spree::BaseController
- Object
- ActionController::Base
- Spree::BaseController
- OrdersController
- Defined in:
- app/controllers/orders_controller.rb
Instance Method Summary collapse
- #accurate_title ⇒ 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 included from SpreeBase
Instance Method Details
#accurate_title ⇒ Object
59 60 61 |
# File 'app/controllers/orders_controller.rb', line 59 def accurate_title I18n.t(:shopping_cart) end |
#edit ⇒ Object
Shows the current incomplete order from the session
20 21 22 |
# File 'app/controllers/orders_controller.rb', line 20 def edit @order = current_order(true) end |
#empty ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/controllers/orders_controller.rb', line 51 def empty if @order = current_order @order.promotion_credits.destroy_all @order.line_items.destroy_all end redirect_to cart_path end |
#populate ⇒ Object
Adds a new item to the order (creating a new order if none already exists)
Parameters can be passed using the following possible parameter configurations:
-
Single variant/quantity pairing
:variants => {variant_id => quantity}
-
Multiple products at once
:products => {product_id => variant_id, product_id => variant_id}, :quantity => quantity :products => {product_id => variant_id, product_id => variant_id}}, :quantity => {variant_id => quantity, variant_id => quantity}
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/orders_controller.rb', line 34 def populate @order = current_order(true) params[:products].each do |product_id,variant_id| quantity = params[:quantity].to_i if !params[:quantity].is_a?(Hash) quantity = params[:quantity][variant_id].to_i if params[:quantity].is_a?(Hash) @order.add_variant(Variant.find(variant_id), quantity) if quantity > 0 end if params[:products] params[:variants].each do |variant_id, quantity| quantity = quantity.to_i @order.add_variant(Variant.find(variant_id), quantity) if quantity > 0 end if params[:variants] redirect_to cart_path end |
#show ⇒ Object
5 6 7 |
# File 'app/controllers/orders_controller.rb', line 5 def show @order = Order.find_by_number(params[:id]) end |
#update ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/orders_controller.rb', line 9 def update @order = current_order if @order.update_attributes(params[:order]) @order.line_items = @order.line_items.select {|li| li.quantity > 0 } redirect_to cart_path else render :edit end end |