Created
June 7, 2016 19:03
-
-
Save darthhomme/3631aa1a5361848043d05695f4c296f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CartController < ApplicationController | |
def add | |
id = params[:id] | |
if session[:cart] then # if a cart has already been created, use it, otherwise make a new one | |
cart = session[:cart] | |
else | |
session[:cart] = {} | |
cart = session[:cart] | |
end | |
if cart[id] then # if the product has been added to the cart, the increase by 1. | |
cart[id] = cart[id] + 1 | |
else | |
cart[id] = 1 | |
end | |
redirect_to :action => :index | |
end | |
def clearCart | |
session[:cart] = nil | |
redirect_to :action => :index | |
end | |
def index | |
@product = Product | |
if session[:cart] then | |
@cart = session[:cart] | |
else | |
@cart = {} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment