Sha256: da62896f7b092259b6e4ff20cb6c07482b5df3b12576e27964e389244f6786b3

Contents?: true

Size: 1.39 KB

Versions: 56

Compression:

Stored size: 1.39 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 = list_products
        expires_in 15.minutes, public: true
        headers['Surrogate-Control'] = "max-age=#{15.minutes}"
      end

      private

      def list_products
        if params[:show_all]
          @products.distinct.page(params[:page])
        else
          @products.distinct.page(params[:page]).per(params[:per_page])
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
solidus_backend-4.4.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.4.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.3.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.2.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.1.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.3.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.3.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.1.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.3.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.3.0 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.2.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.1.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.0.4 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.4.6 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.0.3 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.1.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.2.2 app/controllers/spree/admin/search_controller.rb
solidus_backend-3.4.5 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.2.1 app/controllers/spree/admin/search_controller.rb
solidus_backend-4.2.0 app/controllers/spree/admin/search_controller.rb