Class: RightnowOms::CartItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rightnow_oms/cart_items_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) create



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/rightnow_oms/cart_items_controller.rb', line 12

def create
  if @cart.new_record?
    @cart.save
    session[:cart_id] = @cart.id
  end

  params[:cart_item][:quantity] = 1 if params[:cart_item][:quantity].blank?
  cart_item = @cart.add_item(find_cartable, params[:cart_item])

  respond_to do |format|
    if cart_item.valid?
      format.json { render_for_api :default, json: cart_item, root: :cart_item, status: :created }
    else
      format.json { render json: cart_item.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy



40
41
42
43
44
45
46
# File 'app/controllers/rightnow_oms/cart_items_controller.rb', line 40

def destroy
  @cart_item.destroy

  respond_to do |format|
    format.json { render_for_api :default, json: @cart_item, root: :cart_item, status: :ok }
  end
end

- (Object) index

TODO Unit test needed



8
9
10
# File 'app/controllers/rightnow_oms/cart_items_controller.rb', line 8

def index
  render_for_api :default, json: @cart.cart_items, root: :cart_items, status: :ok
end

- (Object) update



30
31
32
33
34
35
36
37
38
# File 'app/controllers/rightnow_oms/cart_items_controller.rb', line 30

def update
  respond_to do |format|
    if @cart_item.update_attributes(params[:cart_item])
      format.json { render_for_api :default, json: @cart_item, root: :cart_item, status: :ok }
    else
      format.json { render json: @cart_item, status: :unprocessable_entity }
    end
  end
end