Class: Spree::Api::V1::TaxonsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#content_type, #permitted_line_item_attributes
included
Instance Method Details
#create ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 29
def create
authorize! :create, Taxon
@taxon = Spree::Taxon.new(taxon_params)
@taxon.taxonomy_id = params[:taxonomy_id]
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
if taxonomy.nil?
@taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))
invalid_resource!(@taxon) and return
end
@taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
if @taxon.save
respond_with(@taxon, status: 201, default_template: :show)
else
invalid_resource!(@taxon)
end
end
|
#destroy ⇒ Object
58
59
60
61
62
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 58
def destroy
authorize! :destroy, taxon
taxon.destroy
respond_with(taxon, status: 204)
end
|
#index ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 5
def index
@taxons = if taxonomy
taxonomy.root.children
elsif params[:ids]
Spree::Taxon.includes(:children).accessible_by(current_ability).where(id: params[:ids].split(','))
else
Spree::Taxon.includes(:children).accessible_by(current_ability).order(:taxonomy_id, :lft)
end
@taxons = @taxons.ransack(params[:q]).result
@taxons = @taxons.page(params[:page]).per(params[:per_page])
respond_with(@taxons)
end
|
#jstree ⇒ Object
23
24
25
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 23
def jstree
show
end
|
#new ⇒ Object
27
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 27
def new; end
|
#products ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 64
def products
taxon = Spree::Taxon.find(params[:id])
@products = taxon.products.ransack(params[:q]).result
@products = @products.page(params[:page]).per(params[:per_page] || 500)
render 'spree/api/v1/products/index'
end
|
#show ⇒ Object
18
19
20
21
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 18
def show
@taxon = taxon
respond_with(@taxon)
end
|
#update ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'app/controllers/spree/api/v1/taxons_controller.rb', line 49
def update
authorize! :update, taxon
if taxon.update(taxon_params)
respond_with(taxon, status: 200, default_template: :show)
else
invalid_resource!(taxon)
end
end
|