Sha256: 06496f570e48ca8244f6f33289328ea3e5cdcc532d12fa5c31e39bd7ec78ae84

Contents?: true

Size: 1.83 KB

Versions: 62

Compression:

Stored size: 1.83 KB

Contents

module Workarea
  module Search
    class Admin
      class CatalogCategory < Search::Admin
        include Admin::Releasable

        def search_text
          "category #{model.name}"
        end

        def jump_to_text
          model.name
        end

        def jump_to_position
          4
        end

        def facets
          super.merge(issues: issues)
        end

        def displayable_products
          view_model = Workarea::Storefront::CategoryViewModel.wrap(model)
          return [] unless view_model.respond_to?(:products)

          view_model.products
        end

        # This funny business exists because displayable_products depends on
        # product browse indexing, which will be delayed (async).
        #
        def has_products?
          if displayable_products.blank? && model.product_ids.present?
            # Simulate whether it will show up
            # TODO FIX, this is a HACK please forgive my cursed soul
            products = Catalog::Product.any_in(id: model.product_ids.take(100))
            products.any? do |product|
              search_model = Storefront::Product.new(product)

              product.active? &&
                search_model.variant_count > 0 &&
                search_model.inventory.available_to_sell > 0
            end
          else
            displayable_products.present?
          end
        end

        def issues
          result = []
          result << I18n.t('workarea.alerts.issues.no_displayable_products') unless has_products?
          result << I18n.t('workarea.alerts.issues.not_in_taxonomy') unless model.taxon.present?
          result
        end

        def as_document
          super.merge(breadcrumbs: breadcrumbs)
        end

        def breadcrumbs
          Workarea::Navigation::Breadcrumbs.new(model).join(' > ')
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.5.4 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.26 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.5.3 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.25 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.5.2 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.24 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.5.1 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.23 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.22 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.5.0 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.21 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.5.0.beta.1 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.20 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.19 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.18 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.17 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.16 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.15 app/models/workarea/search/admin/catalog_category.rb
workarea-core-3.4.14 app/models/workarea/search/admin/catalog_category.rb