Class: Spree::Api::StockItemsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::StockItemsController
- Defined in:
- app/controllers/spree/api/stock_items_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 18 def create :create, StockItem @stock_item = scope.new(stock_item_params) Spree::StockItem.transaction do if @stock_item.save adjust_stock_item_count_on_hand(count_on_hand_adjustment) respond_with(@stock_item, status: 201, default_template: :show) else invalid_resource!(@stock_item) end end end |
#destroy ⇒ Object
50 51 52 53 54 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 50 def destroy @stock_item = Spree::StockItem.accessible_by(current_ability, :destroy).find(params[:id]) @stock_item.discard respond_with(@stock_item, status: 204) end |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 8 def index @stock_items = paginate(scope.ransack(params[:q]).result) respond_with(@stock_items) end |
#show ⇒ Object
13 14 15 16 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 13 def show @stock_item = scope.find(params[:id]) respond_with(@stock_item) end |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 32 def update @stock_item = Spree::StockItem.accessible_by(current_ability, :update).find(params[:id]) @stock_location = @stock_item.stock_location adjustment = count_on_hand_adjustment params[:stock_item].delete(:count_on_hand) adjustment -= @stock_item.count_on_hand if params[:stock_item][:force] Spree::StockItem.transaction do if @stock_item.update_attributes(stock_item_params) adjust_stock_item_count_on_hand(adjustment) respond_with(@stock_item, status: 200, default_template: :show) else invalid_resource!(@stock_item) end end end |