Class: Spree::Api::LineItemsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::LineItemsController
- Defined in:
- app/controllers/spree/api/line_items_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#new ⇒ Object
9 10 |
# File 'app/controllers/spree/api/line_items_controller.rb', line 9 def new end |
#update ⇒ Object
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 |