Sha256: 4218fa842bb9a2ed11ff7e2ceac48ce5c11b8f007fce7c909f539261218e696a

Contents?: true

Size: 1.28 KB

Versions: 47

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Spree
  module Admin
    class SearchController < Spree::Admin::BaseController
      respond_to :json
      layout false

      # TODO: Clean this up by moving searching out to user_class_extensions
      # And then JSON building with something like Active Model Serializers
      def users
        if params[:ids]
          # split here may be String#split or Array#split, so we must flatten the results
          @users = Spree.user_class.where(id: params[:ids].split(',').flatten)
        else
          @users = Spree.user_class.ransack({
            m: 'or',
            email_start: params[:q],
            addresses_firstname_start: params[:q],
            addresses_lastname_start: params[:q]
          }).result.limit(10)
        end
      end

      def products
        if params[:ids]
          # split here may be String#split or Array#split, so we must flatten the results
          @products = Spree::Product.where(id: params[:ids].split(",").flatten)
        else
          @products = Spree::Product.ransack(params[:q]).result
        end

        @products = @products.distinct.page(params[:page]).per(params[:per_page])
        expires_in 15.minutes, public: true
        headers['Surrogate-Control'] = "max-age=#{15.minutes}"
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
solidus_backend-2.10.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.10.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.10.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.6 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.8.6 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.10.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.10.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.6.6 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.7.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.8.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.10.0.beta1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.7.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.6.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.9.0.rc.1 app/controllers/spree/admin/search_controller.rb