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
Methods inherited from ActionController::Base
Instance Method Details
#accurate_title ⇒ Object
65 66 67 |
# File 'app/controllers/orders_controller.rb', line 65 def accurate_title @order && @order.completed? ? "#{Order.model_name.human} #{@order.number}" : I18n.t(:shopping_cart) end |
#edit ⇒ Object
Shows the current incomplete order from the session
24 25 26 |
# File 'app/controllers/orders_controller.rb', line 24 def edit @order = current_order(true) end |
#empty ⇒ Object
57 58 59 60 61 62 63 |
# File 'app/controllers/orders_controller.rb', line 57 def empty if @order = current_order @order.line_items.destroy_all end respond_with(@order) { |format| format.html { 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}
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/orders_controller.rb', line 38 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].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] fire_event('spree.cart.add') fire_event('spree.order.contents_changed') respond_with(@order) { |format| format.html { redirect_to cart_path } } end |
#show ⇒ Object
7 8 9 10 |
# File 'app/controllers/orders_controller.rb', line 7 def show @order = Order.find_by_number!(params[:id]) respond_with(@order) end |
#update ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/orders_controller.rb', line 12 def update @order = current_order if @order.update_attributes(params[:order]) @order.line_items = @order.line_items.select {|li| li.quantity > 0 } fire_event('spree.order.contents_changed') respond_with(@order) { |format| format.html { redirect_to cart_path } } else respond_with(@order) end end |