Class: Spree::Api::V1::StockItemsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::V1::StockItemsController
show all
- Defined in:
- app/controllers/spree/api/v1/stock_items_controller.rb
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#content_type, #permitted_line_item_attributes
included
Instance Method Details
#create ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/spree/api/v1/stock_items_controller.rb', line 17
def create
authorize! :create, StockItem
count_on_hand = 0
if params[:stock_item].key?(:count_on_hand)
count_on_hand = params[:stock_item][:count_on_hand].to_i
end
@stock_item = scope.new(stock_item_params)
if @stock_item.save
@stock_item.adjust_count_on_hand(count_on_hand)
respond_with(@stock_item, status: 201, default_template: :show)
else
invalid_resource!(@stock_item)
end
end
|
#destroy ⇒ Object
58
59
60
61
62
|
# File 'app/controllers/spree/api/v1/stock_items_controller.rb', line 58
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
7
8
9
10
|
# File 'app/controllers/spree/api/v1/stock_items_controller.rb', line 7
def index
@stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
respond_with(@stock_items)
end
|
#show ⇒ Object
12
13
14
15
|
# File 'app/controllers/spree/api/v1/stock_items_controller.rb', line 12
def show
@stock_item = scope.find(params[:id])
respond_with(@stock_item)
end
|
#update ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/spree/api/v1/stock_items_controller.rb', line 34
def update
@stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
if params[:stock_item].key?(:backorderable)
@stock_item.backorderable = params[:stock_item][:backorderable]
@stock_item.save
end
count_on_hand = 0
if params[:stock_item].key?(:count_on_hand)
count_on_hand = params[:stock_item][:count_on_hand].to_i
params[:stock_item].delete(:count_on_hand)
end
updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)
: @stock_item.adjust_count_on_hand(count_on_hand)
if updated
respond_with(@stock_item, status: 200, default_template: :show)
else
invalid_resource!(@stock_item)
end
end
|