Class: RightnowOms::CartItemsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  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

#destroyObject



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 json: nil, status: :ok }
  end
end

#indexObject

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

#updateObject



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

def update
  if params[:cart_item]
    params[:cart_item].delete(:original_price)
    params[:cart_item].delete(:base_quantity)
  end

  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.errors, status: :unprocessable_entity }
    end
  end
end