Class: Spree::Api::V1::LineItemsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::V1::LineItemsController
show all
- Defined in:
- app/controllers/spree/api/v1/line_items_controller.rb
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#content_type, #map_nested_attributes_keys, #permitted_line_item_attributes
included
Instance Method Details
#create ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 9
def create
variant = Spree::Variant.find(params[:line_item][:variant_id])
@line_item = order.contents.add(
variant,
params[:line_item][:quantity] || 1,
line_item_params[:options] || {}
)
if @line_item.errors.empty?
respond_with(@line_item, status: 201, default_template: :show)
else
invalid_resource!(@line_item)
end
end
|
#destroy ⇒ Object
34
35
36
37
38
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 34
def destroy
@line_item = find_line_item
@order.contents.remove_line_item(@line_item)
respond_with(@line_item, status: 204)
end
|
#update ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 24
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
|