Class: Spree::Api::OrdersController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#cancelObject



40
41
42
43
# File 'app/controllers/spree/api/orders_controller.rb', line 40

def cancel
  @order.cancel!
  render :show
end

#createObject



19
20
21
22
23
# File 'app/controllers/spree/api/orders_controller.rb', line 19

def create
  nested_params[:line_items_attributes] = sanitize_line_items(nested_params[:line_items_attributes])
  @order = Order.build_from_api(current_api_user, nested_params)
  respond_with(@order, :default_template => :show, :status => 201)
end

#emptyObject



45
46
47
48
49
# File 'app/controllers/spree/api/orders_controller.rb', line 45

def empty
  @order.empty!
  @order.update!
  render :text => nil, :status => 200
end

#indexObject

Raises:

  • (CanCan::AccessDenied)


8
9
10
11
12
13
# File 'app/controllers/spree/api/orders_controller.rb', line 8

def index
  # should probably look at turning this into a CanCan step
  raise CanCan::AccessDenied unless current_api_user.has_spree_role?("admin")
  @orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  respond_with(@orders)
end

#showObject



15
16
17
# File 'app/controllers/spree/api/orders_controller.rb', line 15

def show
  respond_with(@order)
end

#updateObject



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

def update
  # Parsing line items through as an update_attributes call in the API will result in
  # many line items for the same variant_id being created. We must be smarter about this,
  # hence the use of the update_line_items method, defined within order_decorator.rb.
  line_items_params = sanitize_line_items(nested_params.delete("line_items_attributes"))
  if @order.update_attributes(nested_params)
    @order.update_line_items(line_items_params)
    @order.line_items.reload
    @order.update!
    respond_with(@order, :default_template => :show)
  else
    invalid_resource!(@order)
  end
end