Class: Spree::PageSections::FeaturedProduct

Inherits:
Spree::PageSection show all
Defined in:
app/models/spree/page_sections/featured_product.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 Method Summary collapse

Methods inherited from Spree::PageSection

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

Instance Method Details

#blocks_available?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/spree/page_sections/featured_product.rb', line 41

def blocks_available?
  true
end

#can_sort_blocks?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/spree/page_sections/featured_product.rb', line 45

def can_sort_blocks?
  true
end

#default_blocksObject



30
31
32
33
34
35
36
37
38
39
# File 'app/models/spree/page_sections/featured_product.rb', line 30

def default_blocks
  [
    Spree::PageBlocks::Products::Title.new,
    Spree::PageBlocks::Products::Price.new(text: 'Price', preferred_text_alignment: 'left'),
    Spree::PageBlocks::Products::VariantPicker.new,
    Spree::PageBlocks::Products::QuantitySelector.new,
    Spree::PageBlocks::Products::BuyButtons.new,
    Spree::PageBlocks::Products::Share.new(text: 'Share')
  ]
end

#icon_nameObject



6
7
8
# File 'app/models/spree/page_sections/featured_product.rb', line 6

def icon_name
  'star'
end

#productObject



10
11
12
13
14
15
16
17
18
# File 'app/models/spree/page_sections/featured_product.rb', line 10

def product
  return @product if defined?(@product)

  includes = [
    { variants: { images: [], prices: [], stock_items: [], stock_locations: [], option_values: :option_type } },
  ]

  @product ||= store.products.includes(includes).find_by(id: preferred_product_id)
end

#product_nameObject



26
27
28
# File 'app/models/spree/page_sections/featured_product.rb', line 26

def product_name
  product&.name
end

#vendor_nameObject



20
21
22
23
24
# File 'app/models/spree/page_sections/featured_product.rb', line 20

def vendor_name
  return unless defined?(Spree::Vendor)

  @vendor_name ||= product&.vendor&.display_name || 'Brand'
end