Class: Spree::Api::V1::OrdersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/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

Methods included from ControllerSetup

included

Instance Method Details

#addressObject



31
32
33
34
35
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 31

def address
  order.build_ship_address(params[:shipping_address]) if params[:shipping_address]
  order.build_bill_address(params[:billing_address]) if params[:billing_address]
  next!
end

#cancelObject



48
49
50
51
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 48

def cancel
  order.cancel!
  render :show
end

#createObject



16
17
18
19
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 16

def create
  @order = Order.build_from_api(current_api_user, nested_params)
  next!(:status => 201)
end

#deliveryObject



37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 37

def delivery
  begin
    ShippingMethod.find(params[:shipping_method_id])
  rescue ActiveRecord::RecordNotFound
    render :invalid_shipping_method, :status => 422
  else
    order.update_attribute(:shipping_method_id, params[:shipping_method_id])
    next!
  end
end

#emptyObject



53
54
55
56
57
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 53

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

#indexObject

Raises:

  • (CanCan::AccessDenied)


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

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])
end

#showObject



13
14
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 13

def show
end

#updateObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 21

def update
  authorize! :update, Order
  if order.update_attributes(nested_params)
    order.update!
    render :show
  else
    invalid_resource!(order)
  end
end