Class: Spree::Api::LineItemsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/line_items_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/api/line_items_controller.rb', line 12

def create
  variant = Spree::Variant.find(params[:line_item][:variant_id])
  begin
    @line_item = @order.contents.add(
      variant,
      params[:line_item][:quantity] || 1,
      options: line_item_params[:options].to_h
    )
    respond_with(@line_item, status: 201, default_template: :show)
  rescue ActiveRecord::RecordInvalid => error
    invalid_resource!(error.record)
  end
end

#destroyObject



36
37
38
39
40
# File 'app/controllers/spree/api/line_items_controller.rb', line 36

def destroy
  @line_item = find_line_item
  @order.contents.remove_line_item(@line_item)
  respond_with(@line_item, status: 204)
end

#newObject



9
10
# File 'app/controllers/spree/api/line_items_controller.rb', line 9

def new
end

#updateObject



26
27
28
29
30
31
32
33
34
# File 'app/controllers/spree/api/line_items_controller.rb', line 26

def update
  @line_item = find_line_item
  if @order.contents.update_cart(line_items_attributes)
    @line_item.reload
    respond_with(@line_item, default_template: :show)
  else
    invalid_resource!(@line_item)
  end
end