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
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 16 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
48 49 50 51 52 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 48 def destroy @stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id]) @stock_item.destroy respond_with(@stock_item, status: 204) end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 6 def index @stock_items = paginate(scope.ransack(params[:q]).result) respond_with(@stock_items) end |
#show ⇒ Object
11 12 13 14 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 11 def show @stock_item = scope.find(params[:id]) respond_with(@stock_item) end |
#update ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/spree/api/stock_items_controller.rb', line 30 def update @stock_item = 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 |