Sha256: 996c0be52113d402b5c7633ddec54f73715380946c17d65b636d2018321f5f96

Contents?: true

Size: 1.23 KB

Versions: 18

Compression:

Stored size: 1.23 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],
            firstname_or_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

18 entries across 18 versions & 1 rubygems

Version Path
solidus_backend-2.11.17 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.16 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.15 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.14 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.13 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.12 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.11 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.10 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.9 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.8 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.7 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.6 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-2.11.0 app/controllers/spree/admin/search_controller.rb