Sha256: 8c1c1a5cf22ba1134d465f663ed8c57bd44d77df0fa77062c7384198c1fa5f53

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 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],
            name_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

10 entries across 10 versions & 1 rubygems

Version Path
solidus_backend-3.0.8 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.7 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.6 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.0.0.rc2 app/controllers/spree/admin/search_controller.rb