Module: ShopBunny::CartControllerModule

Included in:
CartsController
Defined in:
lib/shop_bunny/cart_controller_module.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(clazz) ⇒ Object



3
4
5
6
7
# File 'lib/shop_bunny/cart_controller_module.rb', line 3

def self.included(clazz)
  clazz.send(:respond_to, :html, :json)
  clazz.send(:before_filter, :find_cart)
  clazz.send(:before_filter, :find_item, :only => [:add_item, :remove_item])
end

Instance Method Details

#add_itemObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shop_bunny/cart_controller_module.rb', line 13

def add_item
  if !params[:quantity].blank?
    quantity = params[:quantity].to_i
  else
    quantity = 1
  end
  @cart.add_item(@item, :quantity => quantity) if @item
  respond_with @cart do |format|
    format.html { redirect_to cart_path }
  end
end

#remove_itemObject



25
26
27
28
29
30
# File 'lib/shop_bunny/cart_controller_module.rb', line 25

def remove_item
  @cart.remove_item(@item) if @item
  respond_with @cart do |format|
    format.html { redirect_to cart_path }
  end
end

#showObject



9
10
11
# File 'lib/shop_bunny/cart_controller_module.rb', line 9

def show
  respond_with @cart
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/shop_bunny/cart_controller_module.rb', line 32

def update
  @cart.update_attributes(params[:cart])
  respond_with @cart do |format|
    format.html { 
      if @cart.errors.empty?
        redirect_to after_update_path
    else
      render :show
    end
    }
  end
end