Sha256: 81b82111922b9a3c54d936d60f98ad4755d9573aa44bc6fc33e4f32fa0bd8c61

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

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 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])
    end
  end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecom-0.1.1 app/controllers/ecom/cart_controller.rb