app/controllers/ecom/cart_controller.rb in ecom-0.1.1 vs app/controllers/ecom/cart_controller.rb in ecom-0.2.0
- old
+ new
@@ -1,47 +1,37 @@
require_dependency "ecom/application_controller"
module Ecom
class CartController < ApplicationController
- before_filter :authenticate_user!
- before_filter :get_cart_value
+ 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
+ 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
- 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
-
- 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
-
- 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
-
- protected
-
- def get_cart_value
- if session[:cart_id].nil?
- @cart = Purchase.create
- session[:cart_id] = @cart.id
- @cart
- else
- Purchase.find(session[:cart_id])
+ protected
+
+ def get_cart_value
+ if session[:cart_id].nil?
+ @cart = Purchase.create
+ session[:cart_id] = @cart.id
+ @cart
+ else
+ @cart = Purchase.find(session[:cart_id])
+ end
end
- end
+
end
end