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, #permitted_line_item_attributes
included
Instance Method Details
#create ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 11
def create
variant = Spree::Variant.find(params[:line_item][:variant_id])
@line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: order,
variant: variant,
quantity: params[:line_item][:quantity],
options: line_item_params[:options]).value
if @line_item.errors.empty?
respond_with(@line_item, status: 201, default_template: :show)
else
invalid_resource!(@line_item)
end
end
|
#destroy ⇒ Object
36
37
38
39
40
41
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 36
def destroy
@line_item = find_line_item
Spree::Dependencies.cart_remove_line_item_service.constantize.call(order: @order, line_item: @line_item)
respond_with(@line_item, status: 204)
end
|
#new ⇒ Object
9
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 9
def new; end
|
#update ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/spree/api/v1/line_items_controller.rb', line 25
def update
@line_item = find_line_item
if Spree::Dependencies.cart_update_service.constantize.call(order: @order, params: line_items_attributes).success?
@line_item.reload
respond_with(@line_item, default_template: :show)
else
invalid_resource!(@line_item)
end
end
|