Class: Spree::Page
Direct Known Subclasses
Spree::Pages::Account, Spree::Pages::Cart, Spree::Pages::Checkout, Spree::Pages::Custom, Spree::Pages::Homepage, Spree::Pages::Login, Spree::Pages::Password, Spree::Pages::Post, Spree::Pages::PostList, Spree::Pages::ProductDetails, Spree::Pages::SearchResults, Spree::Pages::ShopAll, Spree::Pages::Taxon, Spree::Pages::TaxonList, Spree::Pages::Wishlist
Instance Method Summary
collapse
#preview?
Instance Method Details
#create_preview ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/models/spree/page.rb', line 67
def create_preview
return self if preview?
ActiveRecord::Base.connected_to(role: :writing) do
ApplicationRecord.transaction do
new_preview = dup
new_preview.parent = self
new_preview.duplicating = true
new_preview.save!
sections.includes(:links, { asset_attachment: :blob }, { blocks: [:rich_text_text, :links] }).each do |section|
section.deep_clone(new_preview)
end
new_preview
end
end
end
|
#custom? ⇒ Boolean
128
129
130
|
# File 'app/models/spree/page.rb', line 128
def custom?
type == 'Spree::Pages::Custom'
end
|
#customizable? ⇒ Boolean
102
103
104
|
# File 'app/models/spree/page.rb', line 102
def customizable?
false
end
|
#default_sections ⇒ Object
98
99
100
|
# File 'app/models/spree/page.rb', line 98
def default_sections
[]
end
|
#display_name ⇒ Object
120
121
122
123
124
125
126
|
# File 'app/models/spree/page.rb', line 120
def display_name
if custom?
name
else
name.titleize
end
end
|
#duplicate(target_pageable) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'app/models/spree/page.rb', line 132
def duplicate(target_pageable)
duplicated_page = dup
duplicated_page.duplicating = true
duplicated_page.pageable = target_pageable
duplicated_page.save!
sections_scope = sections.includes(:links, :blocks, { asset_attachment: :blob },
{ blocks: [:rich_text_text, :links, { asset_attachment: :blob }] })
sections_scope.each { |section| section.deep_clone(duplicated_page) }
duplicated_page
end
|
#icon_name ⇒ Object
55
56
57
|
# File 'app/models/spree/page.rb', line 55
def icon_name
'file-earmark-richtext'
end
|
#layout_sections? ⇒ Boolean
110
111
112
|
# File 'app/models/spree/page.rb', line 110
def layout_sections?
true
end
|
#linkable? ⇒ Boolean
106
107
108
|
# File 'app/models/spree/page.rb', line 106
def linkable?
false
end
|
#preview_url(theme_preview = nil, page_preview = nil) ⇒ Object
114
115
116
117
118
|
# File 'app/models/spree/page.rb', line 114
def preview_url(theme_preview = nil, page_preview = nil)
return if page_builder_url.blank?
"#{page_builder_url}?#{url_query_params(theme_preview, page_preview).to_query}"
end
|
Promotes the page preview to the main page
87
88
89
90
91
92
93
94
95
96
|
# File 'app/models/spree/page.rb', line 87
def promote
return unless preview?
ApplicationRecord.transaction do
old_page = parent
old_page.page_links.update_all(linkable_id: id)
update(parent: nil)
Spree::Page.find(old_page.id).destroy
end
end
|
#store ⇒ Object
59
60
61
62
63
64
65
|
# File 'app/models/spree/page.rb', line 59
def store
if pageable.is_a?(Spree::Store)
pageable
else
pageable.store
end
end
|
#theme ⇒ Object
145
146
147
148
149
150
151
|
# File 'app/models/spree/page.rb', line 145
def theme
@theme ||= if pageable.is_a?(Spree::Theme)
pageable
else
pageable.default_theme
end
end
|