Class: Spree::Api::OrdersController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::OrdersController
- Defined in:
- app/controllers/spree/api/orders_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
- #cancel ⇒ Object
- #create ⇒ Object
- #current ⇒ Object
- #empty ⇒ Object
- #index ⇒ Object
- #mine ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#cancel ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/spree/api/orders_controller.rb', line 25 def cancel :update, @order, params[:token] @order.canceled_by(current_api_user) respond_with(@order, default_template: :show) end |
#create ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/spree/api/orders_controller.rb', line 31 def create :create, Order if can?(:admin, Order) @order = Spree::Core::Importer::Order.import(determine_order_user, order_params) respond_with(@order, default_template: :show, status: 201) else @order = Spree::Order.create!(user: current_api_user, store: current_store) if @order.contents.update_cart order_params respond_with(@order, default_template: :show, status: 201) else invalid_resource!(@order) end end end |
#current ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/controllers/spree/api/orders_controller.rb', line 88 def current if current_api_user && @order = current_api_user.last_incomplete_spree_order(store: current_store) respond_with(@order, default_template: :show, locals: { root_object: @order }) else head :no_content end end |
#empty ⇒ Object
47 48 49 50 51 |
# File 'app/controllers/spree/api/orders_controller.rb', line 47 def empty :update, @order, order_token @order.empty! respond_with(@order, default_template: :show) end |
#index ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/spree/api/orders_controller.rb', line 53 def index :admin, Order orders_includes = [ { user: :store_credits }, :line_items, :valid_store_credit_payments ] @orders = paginate( Spree::Order .ransack(params[:q]) .result .includes(orders_includes) ) respond_with(@orders) end |
#mine ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'app/controllers/spree/api/orders_controller.rb', line 96 def mine if current_api_user @orders = current_api_user.orders.by_store(current_store).reverse_chronological.ransack(params[:q]).result @orders = paginate(@orders) else render "spree/api/errors/unauthorized", status: :unauthorized end end |
#show ⇒ Object
69 70 71 72 |
# File 'app/controllers/spree/api/orders_controller.rb', line 69 def show :show, @order, order_token respond_with(@order) end |
#update ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/spree/api/orders_controller.rb', line 74 def update :update, @order, order_token if @order.contents.update_cart(order_params) user_id = params[:order][:user_id] if can?(:admin, @order) && user_id @order.associate_user!(Spree.user_class.find(user_id)) end respond_with(@order, default_template: :show) else invalid_resource!(@order) end end |