Module: Spree::PageBuilder::StoreDecorator

Defined in:
app/models/spree/page_builder/store_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/spree/page_builder/store_decorator.rb', line 4

def self.prepended(base)
  base.include Spree::HasPageLinks
  base.include Spree::Stores::Socials

  # Page Builder associations
  base.has_many :themes, -> { without_previews }, class_name: 'Spree::Theme', dependent: :destroy, inverse_of: :store
  base.has_many :theme_previews,
                -> { only_previews },
                class_name: 'Spree::Theme',
                through: :themes,
                source: :previews,
                inverse_of: :store,
                dependent: :destroy
  base.has_one :default_theme, -> { without_previews.where(default: true) }, class_name: 'Spree::Theme', inverse_of: :store
  base.alias_method :theme, :default_theme
  base.has_many :theme_pages, class_name: 'Spree::Page', through: :themes, source: :pages
  base.has_many :theme_page_previews, class_name: 'Spree::Page', through: :theme_pages, source: :previews
  base.has_many :pages, -> { without_previews.custom }, class_name: 'Spree::Pages::Custom', dependent: :destroy, as: :pageable
  base.has_many :page_previews, class_name: 'Spree::Pages::Custom', through: :pages, as: :pageable, source: :previews

  base.after_create :create_default_theme

  base.has_rich_text :checkout_message

  # Storefront-specific attachments
  base.has_one_attached :favicon_image, service: Spree.public_storage_service_name
  base.has_one_attached :social_image, service: Spree.public_storage_service_name

  base.validates :favicon_image, :social_image, content_type: Rails.application.config.active_storage.web_image_content_types

  base.preference :index_in_search_engines, :boolean, default: false
  base.preference :password_protected, :boolean, default: false
  base.store_accessor :private_metadata, :storefront_password

  base.translates(:facebook, :twitter, :instagram, column_fallback: !Spree.always_use_translations?)
end

Instance Method Details

#faviconObject



41
42
43
44
45
# File 'app/models/spree/page_builder/store_decorator.rb', line 41

def favicon
  return unless favicon_image.attached? && favicon_image.variable?

  favicon_image.variant(resize_to_limit: [32, 32])
end