Class: Spree::Pages::Custom

Inherits:
Spree::Page show all
Defined in:
app/models/spree/pages/custom.rb

Instance Method Summary collapse

Methods inherited from Spree::Page

#create_preview, #custom?, #display_name, #duplicate, #icon_name, #layout_sections?, #preview_url, #store, #theme

Methods included from Spree::Previewable

#preview?

Instance Method Details

#customizable?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'app/models/spree/pages/custom.rb', line 4

def customizable?
  true
end

#default_sectionsObject



18
19
20
21
22
23
# File 'app/models/spree/pages/custom.rb', line 18

def default_sections
  [
    Spree::PageSections::PageTitle.new,
    Spree::PageSections::RichText.new
  ]
end

#linkable?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/spree/pages/custom.rb', line 8

def linkable?
  true
end

#page_builder_urlObject



12
13
14
15
16
# File 'app/models/spree/pages/custom.rb', line 12

def page_builder_url
  return unless page_builder_url_exists?(:page_path)

  Spree::Core::Engine.routes.url_helpers.page_path(self)
end

#promoteObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/spree/pages/custom.rb', line 25

def promote
  return unless preview?

  ApplicationRecord.transaction do
    old_page = parent
    old_page.page_links.update_all(linkable_id: id)
    update(parent: nil) # clear reference to the old page
    Spree::Page.find(old_page.id).destroy # destroy the old page with their other previews, etc.
    update_columns(slug: old_page.slug)
  end
end