Class: Spree::Api::StockItemsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys
Instance Method Details
#create ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/spree/api/stock_items_controller.rb', line 16
def create
authorize! :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
49
50
51
52
53
|
# File 'app/controllers/spree/api/stock_items_controller.rb', line 49
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 = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/spree/api/stock_items_controller.rb', line 31
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
|