Class: Spree::PageSections::FeaturedTaxon

Inherits:
Spree::PageSection show all
Defined in:
app/models/spree/page_sections/featured_taxon.rb

Constant Summary

Constants inherited from Spree::PageSection

Spree::PageSection::BACKGROUND_COLOR_DEFAULT, Spree::PageSection::BORDER_COLOR_DEFAULT, Spree::PageSection::BOTTOM_BORDER_WIDTH_DEFAULT, Spree::PageSection::BOTTOM_PADDING_DEFAULT, Spree::PageSection::TEXT_COLOR_DEFAULT, Spree::PageSection::TOP_BORDER_WIDTH_DEFAULT, Spree::PageSection::TOP_PADDING_DEFAULT

Instance Attribute Summary

Attributes inherited from Spree::PageSection

#default_blocks

Instance Method Summary collapse

Methods inherited from Spree::PageSection

#available_blocks_to_add, #blocks_available?, #can_be_deleted?, #can_be_sorted?, #can_sort_blocks?, #copy_rich_text_fields_from, #deep_clone, #deep_clone_links, #dup, #lazy_path, #restore_design_settings_to_defaults, #rich_text_fields, #role, role, #theme, #to_partial_path

Instance Method Details

#description_to_useObject



42
43
44
# File 'app/models/spree/page_sections/featured_taxon.rb', line 42

def description_to_use
  @description_to_use ||= preferred_use_description_from_admin && description.blank? ? taxon&.description : description
end

#display_nameObject



46
47
48
# File 'app/models/spree/page_sections/featured_taxon.rb', line 46

def display_name
  @display_name ||= preferred_heading.present? ? "#{preferred_heading} - #{name}" : name
end

#icon_nameObject



30
31
32
# File 'app/models/spree/page_sections/featured_taxon.rb', line 30

def icon_name
  'tags'
end

#lazy?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/spree/page_sections/featured_taxon.rb', line 34

def lazy?
  !Rails.env.test?
end

#products(currency) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/spree/page_sections/featured_taxon.rb', line 50

def products(currency)
  Spree::Deprecation.warn(
    'FeaturedTaxon#products is deprecated and will be removed in Spree 6.0. ' \
    'Please use taxon_products(featured_taxon.taxon) helper method in views instead'
  )

  @products ||= begin
    finder_params = {
      store: store,
      filter: { taxons: preferred_taxon_id },
      currency: currency,
      sort_by: 'default'
    }

    products_finder = Spree::Dependencies.products_finder.constantize
    products_finder.new(scope: store.products, params: finder_params).execute.limit(preferred_max_products_to_show)
  end
end

#taxonObject



38
39
40
# File 'app/models/spree/page_sections/featured_taxon.rb', line 38

def taxon
  @taxon ||= store.taxons.find_by(id: preferred_taxon_id) if preferred_taxon_id.present?
end