Class | StoreController
In: | app/controllers/store_controller.rb
Parent: | ApplicationController

### Methods

add_to_cart checkout empty_cart index save_order

### Public Instance methods

add_to_cart()

[Source]

        # File app/controllers/store_controller.rb, line 8
     8:   def add_to_cart
     9:     begin
    10:       product = Product.find(params[:id])
    11:     rescue ActiveRecord::RecordNotFound
    12:       logger.error("Próba dostępu do nieistniejącego produktu: #{params[:id]}")
    13:       redirect_to_index("Nieprawidłowy produkt")
    14:     else
    15:       @cart = find_cart
    16:       @current_item = @cart.add_product(product)
    17:       redirect_to_index unless request.xhr?
    18:     end
    19:   end

checkout()

[Source]

        # File app/controllers/store_controller.rb, line 26
    26:   def checkout
    27:     if @cart.items.empty?
    28:       redirect_to_index("Twój koszyk jest pusty")
    29:     else
    30:       @order = Order.new
    31:     end
    32:   end

empty_cart()

[Source]

        # File app/controllers/store_controller.rb, line 21
    21:   def empty_cart
    22:     session[:cart] = nil
    23:     redirect_to_index
    24:   end

index()

[Source]

       # File app/controllers/store_controller.rb, line 4
    4:   def index
    5:     @products = Product.find_products_for_sale
    6:   end

save_order()

[Source]

        # File app/controllers/store_controller.rb, line 34
    34:   def save_order
    35:     @order = Order.new(params[:order])
    36:     @order.add_line_items_from_cart(@cart)
    37:     if @order.save
    38:       session[:cart] = nil
    39:       redirect_to_index("Dziękujemy za złożenie zamówienia")
    40:     else
    41:       render :action => :checkout
    42:     end
    43:   end

[Validate]