Sha256: 692a6bf4b3f5dc5b843e422a9b59bb36be9359ffc292897e109cef6adcf77d5e

Contents?: true

Size: 1.81 KB

Versions: 34

Compression:

Stored size: 1.81 KB

Contents

module Workarea
  module Search
    module ProductDisplayRules
      def product_display_query_clauses(allow_displayable_when_out_of_stock: true)
        [
          { term: { type: 'product' } },
          { range: { "numeric.variant_count": { gt: 0 } } },
          inventory_display_clause(
            allow_displayable_when_out_of_stock: allow_displayable_when_out_of_stock
          ),
          active_for_release_clause
        ]
      end

      def displayable_when_out_of_stock_sort_clause
        {
          'sorts.inventory_score': {
            order: 'desc',
            missing: '_first',
            unmapped_type: 'float'
          }
        }
      end

      private

      def inventory_display_clause(allow_displayable_when_out_of_stock: true)
        result = { bool: { should: [{ range: { 'numeric.inventory': { gt: 0 } } }] } }

        if allow_displayable_when_out_of_stock
          result[:bool][:should] << {
            term: { 'facets.inventory_policies': 'displayable_when_out_of_stock' }
          }
        end

        result
      end

      def active_for_release_clause
        if Release.current.blank?
          { term: { 'active.now' => true } }
        else
          {
            bool: {
              should: [
                { term: { "active.#{Release.current.id}" => true } },
                {
                  bool: {
                    must: [
                      { term: { 'active.now' => true } },
                      {
                        bool: {
                          must_not: {
                            exists: { field: "active.#{Release.current.id}" }
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.44 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.43 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.42 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.41 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.40 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.39 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.38 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.37 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.36 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.35 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.34 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.33 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.32 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.31 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.30 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.29 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.28 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.27 app/queries/workarea/search/product_display_rules.rb
workarea-core-3.4.26 app/queries/workarea/search/product_display_rules.rb