Class: Ecom::CartController

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

Instance Method Summary collapse

Instance Method Details

#addObject



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/ecom/cart_controller.rb', line 5

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

#removeObject



15
16
17
18
19
20
21
# File 'app/controllers/ecom/cart_controller.rb', line 15

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