Class: Ecom::CartController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ecom/cart_controller.rb

Instance Method Summary collapse

Instance Method Details

#addObject



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/ecom/cart_controller.rb', line 8

def add
  @cart.save
  session[:cart_id] = @cart.id
  product = Product.find(params[:id])
  item = LineItem.new
  item.make_items(@cart.id, product.id, product.base_price)
  @cart.recalculate_price!
  flash[:notice] = "Product Added to Cart"
  redirect_to cart_path
end

#checkoutObject



27
28
29
30
31
32
# File 'app/controllers/ecom/cart_controller.rb', line 27

def checkout
  @cart.checkout!
  session.delete(:cart_id)
  flash[:notice] = "Thank your for the Order! We will e-mail you with the shipping info."
  redirect_to root_path
end

#removeObject



19
20
21
22
23
24
25
# File 'app/controllers/ecom/cart_controller.rb', line 19

def remove
  item = @cart.line_items.find(params[:id])
  item.destroy
  @cart.recalculate_price!
  flash[:notice] = "Product Deleted from Cart"
  redirect_to cart_path
end