Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: e273216e17
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (38 sloc) 0.845 kB
class StoreController < ApplicationController
def index
@products = Product.available_items
end
def add_to_cart
product = Product.find(params[:id])
@cart = get_cart
@cart.add_line_item(product)
redirect_to store_path
end
def show_cart
@cart = get_cart
@items = @cart.items
if @items.empty?
redirect_to store_path
flash[:notice] = "Your cart is currently empty"
else
render 'shoppingcart'
end
end
def empty_cart
@cart = get_cart
@cart.empty_cart_contents!
flash[:notice] = ' Your cart is now empty'
redirect_to store_path
end
def checkout
@cart = get_cart
@items = @cart.items
if @items.empty?
redirect_to root_path("There's nothing in your cart")
end
end
private
def get_cart
session[:cart] ||= Cart.new
end
end
Jump to Line
Something went wrong with that request. Please try again.