Sha256: b023269a95256c7cd3699d71730fbd8f201f04885f3e5f0acbc636e9fd22c4c7

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

require_dependency "ecom/application_controller"

module Ecom
  class CartController < ApplicationController
    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
    
    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

Version data entries

1 entries across 1 versions & 1 rubygems

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