Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 91b71f3a06
Fetching contributors…

Cannot retrieve contributors at this time

36 lines (26 sloc) 0.557 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
render 'shoppingcart'
end
def empty_cart
@cart = get_cart
@cart.empty_cart_contents!
flash[:notice] = ' Your cart is now empty'
redirect_to store_path
end
private
def get_cart
session[:cart] ||= Cart.new
end
end
Jump to Line
Something went wrong with that request. Please try again.