Sha256: d550da4ba93b5be8f1d561e2b9793c5607cd5477b28d1d32fc957e1f1ce6c370

Contents?: true

Size: 935 Bytes

Versions: 8

Compression:

Stored size: 935 Bytes

Contents

module Spree
  module Api
    module V2
      class TaxonsController < Spree::Api::V2::BaseController
        skip_before_action :authenticate_user, only: [:index, :show]

        def index
          render_collection taxons
        end

        def show
          render_instance taxon
        end

        private

        def taxon
          if params[:taxon_id].present?
            taxons.includes(parent: taxon_associations).find(params[:taxon_id]).parent
          else
            taxons.find(params[:id])
          end
        end

        def taxons
          if params[:taxonomy_id].present?
            Spree::Taxonomy.find(params[:taxonomy_id]).taxons
              .includes(*taxon_associations.-([:taxonomy]))
          else
            Spree::Taxon.includes(*taxon_associations)
          end
        end

        def taxon_associations
          [:products, :taxonomy, :parent]
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
solidus_json_api-0.3.1 app/controllers/spree/api/v2/taxons_controller.rb
solidus_json_api-0.3.0 app/controllers/spree/api/v2/taxons_controller.rb
spree_api_v2-0.2.2 app/controllers/spree/api/v2/taxons_controller.rb
solidus_api_v2-0.2.2 app/controllers/spree/api/v2/taxons_controller.rb
solidus_api_v2-0.2.1 app/controllers/spree/api/v2/taxons_controller.rb
spree_api_v2-0.2.1 app/controllers/spree/api/v2/taxons_controller.rb
spree_api_v2-0.2.0 app/controllers/spree/api/v2/taxons_controller.rb
solidus_api_v2-0.2.0 app/controllers/spree/api/v2/taxons_controller.rb