spree_storefront 5.0.4 → 5.1.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/spree/locale_urls.rb +13 -1
- data/app/controllers/concerns/spree/storefront/devise_concern.rb +42 -0
- data/app/controllers/spree/addresses_controller.rb +5 -1
- data/app/controllers/spree/checkout_controller.rb +27 -9
- data/app/controllers/spree/contacts_controller.rb +1 -1
- data/app/controllers/spree/products_controller.rb +1 -3
- data/app/controllers/spree/store_controller.rb +16 -9
- data/app/controllers/spree/taxons_controller.rb +1 -3
- data/app/helpers/spree/analytics_helper.rb +6 -2
- data/app/helpers/spree/checkout_analytics_helper.rb +1 -1
- data/app/helpers/spree/checkout_helper.rb +1 -1
- data/app/helpers/spree/filters_helper.rb +1 -1
- data/app/helpers/spree/page_helper.rb +15 -0
- data/app/helpers/spree/products_helper.rb +13 -1
- data/app/helpers/spree/storefront_helper.rb +12 -0
- data/app/helpers/spree/storefront_locale_helper.rb +3 -0
- data/app/helpers/spree/theme_helper.rb +76 -0
- data/app/helpers/spree/wishlist_helper.rb +3 -0
- data/app/javascript/spree/storefront/controllers/product_form_controller.js +21 -18
- data/app/javascript/spree/storefront/controllers/slideover_controller.js +2 -0
- data/app/views/devise/registrations/_form.html.erb +2 -2
- data/app/views/devise/sessions/new.html.erb +16 -0
- data/app/views/spree/account/wished_items/create.turbo_stream.erb +1 -0
- data/app/views/spree/addresses/edit.html.erb +4 -0
- data/app/views/spree/addresses/new.html.erb +3 -0
- data/app/views/spree/checkout/edit.html.erb +5 -3
- data/app/views/spree/line_items/create.turbo_stream.erb +1 -0
- data/app/views/spree/line_items/destroy.turbo_stream.erb +2 -0
- data/app/views/spree/products/show.html.erb +2 -1
- data/app/views/themes/default/spree/account/addresses/_address.html.erb +14 -4
- data/app/views/themes/default/spree/account/addresses/_edit_address_modal.html.erb +38 -0
- data/app/views/themes/default/spree/account/addresses/_new_address_modal.html.erb +38 -0
- data/app/views/themes/default/spree/account/addresses/index.html.erb +22 -2
- data/app/views/themes/default/spree/orders/edit.html.erb +2 -0
- data/app/views/themes/default/spree/products/_add_to_cart_button.html.erb +8 -2
- data/app/views/themes/default/spree/products/filters/_taxons.erb +5 -5
- data/app/views/themes/default/spree/shared/_error_messages.html.erb +1 -1
- data/lib/generators/spree/storefront/devise/devise_generator.rb +47 -0
- data/lib/generators/spree/storefront/devise/templates/user_passwords_controller.rb +17 -0
- data/lib/generators/spree/storefront/devise/templates/user_registrations_controller.rb +17 -0
- data/lib/generators/spree/storefront/devise/templates/user_sessions_controller.rb +17 -0
- data/lib/spree/storefront/engine.rb +7 -1
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8bc38aa5cb40c780c3a1fa2f20d1672b4f95986c66261a1833f725a417fb15b
|
4
|
+
data.tar.gz: 4a04f0367d6c4fd8b53a56a1eb3e7f635c4af6c116751367952e4a6153544c4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: befdf20cbbb63756d6f026ffe47502daa56ffbd3db39048a98c3b9a2d1303e2f08475036004e3bd61f123fce1f05ce53d3d710d520a1a569b2daeb263d573ecd
|
7
|
+
data.tar.gz: c78e23552f955bbe171d2db49d883027002a2f7eb0b5532689819ae64b6595f05dcc4df76e0a95e3e88cf1f93e6497cc26666ac8c5a9b3c333cb414fe8983a8f
|
@@ -21,7 +21,19 @@ module Spree
|
|
21
21
|
def redirect_to_default_locale
|
22
22
|
return if params[:locale].blank? || supported_locale?(params[:locale])
|
23
23
|
|
24
|
-
|
24
|
+
# Only include safe parameters in the redirect
|
25
|
+
safe_params = {
|
26
|
+
controller: params[:controller],
|
27
|
+
action: params[:action],
|
28
|
+
locale: nil
|
29
|
+
}
|
30
|
+
|
31
|
+
# Add any additional safe parameters that should be preserved
|
32
|
+
%i[id format currency category_id tag].each do |param|
|
33
|
+
safe_params[param] = params[param] if params[param].present?
|
34
|
+
end
|
35
|
+
|
36
|
+
redirect_to url_for(safe_params)
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# This concern is used to include the necessary methods and helpers for the Devise controllers
|
2
|
+
# It is used to avoid repeating the same code in each controller
|
3
|
+
module Spree
|
4
|
+
module Storefront
|
5
|
+
module DeviseConcern
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
helper_method :title
|
10
|
+
helper_method :stored_location
|
11
|
+
layout 'spree/storefront'
|
12
|
+
|
13
|
+
include Spree::Core::ControllerHelpers::Order
|
14
|
+
include Spree::LocaleUrls
|
15
|
+
include Spree::ThemeConcern
|
16
|
+
include Spree::IntegrationsHelper if defined?(Spree::IntegrationsHelper)
|
17
|
+
|
18
|
+
helper 'spree/wishlist'
|
19
|
+
helper 'spree/currency'
|
20
|
+
helper 'spree/locale'
|
21
|
+
helper 'spree/storefront_locale'
|
22
|
+
helper 'spree/integrations' if defined?(Spree::IntegrationsHelper)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stored_location
|
26
|
+
return unless defined?(after_sign_in_path_for)
|
27
|
+
return unless defined?(store_location_for)
|
28
|
+
return unless defined?(Devise)
|
29
|
+
|
30
|
+
path = after_sign_in_path_for(Devise.mappings.keys.first)
|
31
|
+
|
32
|
+
store_location_for(Devise.mappings.keys.first, path)
|
33
|
+
|
34
|
+
path
|
35
|
+
end
|
36
|
+
|
37
|
+
def password_path(_resource_or_scope = nil)
|
38
|
+
send("#{Spree.user_class.model_name.singular_route_key}_password_path")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -26,6 +26,8 @@ module Spree
|
|
26
26
|
else
|
27
27
|
redirect_to spree.account_addresses_path, notice: Spree.t('address_book.successfully_created')
|
28
28
|
end
|
29
|
+
elsif params[:from_modal].present?
|
30
|
+
render turbo_stream: turbo_stream.update(:new_address_modal, partial: 'spree/account/addresses/new_address_modal', locals: { address: @address }), status: :unprocessable_entity
|
29
31
|
else
|
30
32
|
render action: 'new', status: :unprocessable_entity
|
31
33
|
end
|
@@ -67,8 +69,10 @@ module Spree
|
|
67
69
|
format.html { redirect_to spree.checkout_state_path(@order.token, 'address') }
|
68
70
|
end
|
69
71
|
else
|
70
|
-
|
72
|
+
redirect_back(fallback_location: spree.account_addresses_path)
|
71
73
|
end
|
74
|
+
elsif params[:from_modal].present?
|
75
|
+
render turbo_stream: turbo_stream.update("edit_address_modal_#{@address.id}", partial: 'spree/account/addresses/edit_address_modal', locals: { address: @address }), status: :unprocessable_entity
|
72
76
|
else
|
73
77
|
render :edit, status: :unprocessable_entity
|
74
78
|
end
|
@@ -14,6 +14,7 @@ module Spree
|
|
14
14
|
|
15
15
|
before_action :ensure_order_not_completed, only: [:edit, :update]
|
16
16
|
before_action :ensure_checkout_allowed
|
17
|
+
before_action :check_if_checkout_started, only: :edit
|
17
18
|
before_action :ensure_valid_state, only: [:edit, :update]
|
18
19
|
|
19
20
|
before_action :restart_checkout, only: :edit, if: :should_restart_checkout?
|
@@ -33,13 +34,6 @@ module Spree
|
|
33
34
|
|
34
35
|
# GET /checkout/<token>
|
35
36
|
def edit
|
36
|
-
if checkout_started?
|
37
|
-
track_checkout_started
|
38
|
-
|
39
|
-
@order.accept_marketing = true # TODO: move this to store preferences
|
40
|
-
@order.signup_for_an_account = true # TODO: move this to store preferences
|
41
|
-
end
|
42
|
-
|
43
37
|
track_checkout_step_viewed
|
44
38
|
end
|
45
39
|
|
@@ -179,8 +173,23 @@ module Spree
|
|
179
173
|
flash[:error] = 'You cannot access this checkout'
|
180
174
|
redirect_to_cart
|
181
175
|
elsif try_spree_current_user.nil? && !@order.completed?
|
182
|
-
|
183
|
-
|
176
|
+
if params[:guest] && current_store.prefers_guest_checkout?
|
177
|
+
@order = current_store.
|
178
|
+
orders.
|
179
|
+
create!(current_order_params.except(:token, :user_id)).
|
180
|
+
tap do |order|
|
181
|
+
order.merge!(@order, discard_merged: false)
|
182
|
+
order.disassociate_user!
|
183
|
+
end
|
184
|
+
|
185
|
+
reset_session
|
186
|
+
cookies.permanent.signed[:token] = @order.token
|
187
|
+
|
188
|
+
redirect_to spree.checkout_path(@order.token)
|
189
|
+
else
|
190
|
+
store_location
|
191
|
+
redirect_to spree_login_path
|
192
|
+
end
|
184
193
|
end
|
185
194
|
end
|
186
195
|
|
@@ -227,6 +236,15 @@ module Spree
|
|
227
236
|
end
|
228
237
|
end
|
229
238
|
|
239
|
+
def check_if_checkout_started
|
240
|
+
if checkout_started?
|
241
|
+
track_checkout_started
|
242
|
+
|
243
|
+
@order.accept_marketing = true # TODO: move this to store preferences
|
244
|
+
@order.signup_for_an_account = true # TODO: move this to store preferences
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
230
248
|
def ensure_valid_state
|
231
249
|
redirect_to_state(correct_state) if @order.state != correct_state && !skip_state_validation?
|
232
250
|
end
|
@@ -40,7 +40,7 @@ module Spree
|
|
40
40
|
return if current_store.customer_support_email.present?
|
41
41
|
|
42
42
|
flash[:error] = Spree.t('storefront.contacts.customer_support_email_not_configured')
|
43
|
-
|
43
|
+
redirect_back(fallback_location: root_path)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -77,9 +77,7 @@ module Spree
|
|
77
77
|
# If an old id or a numeric id was used to find the record,
|
78
78
|
# we should do a 301 redirect that uses the current friendly id.
|
79
79
|
if params[:id] != @product.friendly_id
|
80
|
-
|
81
|
-
params.permit!
|
82
|
-
redirect_to url_for(params), status: :moved_permanently
|
80
|
+
redirect_to spree.product_path(@product), status: :moved_permanently
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
@@ -8,6 +8,7 @@ module Spree
|
|
8
8
|
include Spree::PasswordProtected
|
9
9
|
include Spree::WishlistHelper
|
10
10
|
include Spree::AnalyticsHelper
|
11
|
+
include Spree::IntegrationsHelper
|
11
12
|
|
12
13
|
layout :choose_layout
|
13
14
|
|
@@ -17,6 +18,7 @@ module Spree
|
|
17
18
|
helper 'spree/currency'
|
18
19
|
helper 'spree/addresses'
|
19
20
|
helper 'spree/wishlist'
|
21
|
+
helper 'spree/integrations'
|
20
22
|
|
21
23
|
helper_method :title
|
22
24
|
helper_method :title=
|
@@ -28,6 +30,8 @@ module Spree
|
|
28
30
|
:storefront_products_scope, :storefront_products,
|
29
31
|
:default_products_sort, :default_products_finder_params
|
30
32
|
|
33
|
+
helper_method :stored_location
|
34
|
+
|
31
35
|
before_action :redirect_to_default_locale
|
32
36
|
before_action :render_404_if_store_not_exists
|
33
37
|
rescue_from ActionController::InvalidAuthenticityToken, with: :invalid_authenticity_token
|
@@ -69,7 +73,10 @@ module Spree
|
|
69
73
|
:out_of_stock,
|
70
74
|
{
|
71
75
|
options: [store_filter_names_hash],
|
72
|
-
taxon_ids: []
|
76
|
+
taxon_ids: [],
|
77
|
+
taxonomy_ids: [
|
78
|
+
taxon_ids: []
|
79
|
+
]
|
73
80
|
}
|
74
81
|
]
|
75
82
|
)
|
@@ -191,7 +198,8 @@ module Spree
|
|
191
198
|
end
|
192
199
|
|
193
200
|
def redirect_back_or_default(default)
|
194
|
-
|
201
|
+
Spree::Deprecation.warn('redirect_back_or_default is deprecated and will be removed in Spree 5.2. Please use redirect_back(fallback_location: default) instead.')
|
202
|
+
redirect_back(fallback_location: default)
|
195
203
|
end
|
196
204
|
|
197
205
|
def require_user(return_to = nil)
|
@@ -205,16 +213,15 @@ module Spree
|
|
205
213
|
end
|
206
214
|
end
|
207
215
|
|
208
|
-
|
209
|
-
|
210
|
-
def store_location(location = nil)
|
211
|
-
return if try_spree_current_user
|
212
|
-
return unless defined?(store_location_for)
|
216
|
+
def stored_location
|
217
|
+
return unless defined?(after_sign_in_path_for)
|
213
218
|
return unless defined?(Devise)
|
214
219
|
|
215
|
-
|
220
|
+
path = after_sign_in_path_for(Devise.mappings.keys.first)
|
221
|
+
|
222
|
+
store_location(path)
|
216
223
|
|
217
|
-
|
224
|
+
path
|
218
225
|
end
|
219
226
|
|
220
227
|
def redirect_to_cart
|
@@ -33,9 +33,7 @@ module Spree
|
|
33
33
|
# If an old id or a numeric id was used to find the record,
|
34
34
|
# we should do a 301 redirect that uses the current friendly id.
|
35
35
|
if params[:id] != @taxon.friendly_id
|
36
|
-
|
37
|
-
params.permit!
|
38
|
-
redirect_to url_for(params), status: :moved_permanently
|
36
|
+
redirect_to spree.nested_taxons_path(@taxon), status: :moved_permanently
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
@@ -2,7 +2,7 @@ module Spree
|
|
2
2
|
module AnalyticsHelper
|
3
3
|
def analytics_event_handlers
|
4
4
|
@analytics_event_handlers ||= Spree::Analytics.event_handlers.map do |handler|
|
5
|
-
handler.new(user: try_spree_current_user, session: session, request: request)
|
5
|
+
handler.new(user: try_spree_current_user, session: session, request: request, store: Spree::Store.current, visitor_id: visitor_id)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -16,11 +16,15 @@ module Spree
|
|
16
16
|
rescue => e
|
17
17
|
Rails.error.report(
|
18
18
|
e,
|
19
|
-
context: { event_name: event_name,
|
19
|
+
context: { event_name: event_name, record: record },
|
20
20
|
source: 'spree.storefront'
|
21
21
|
)
|
22
22
|
end
|
23
23
|
|
24
|
+
def visitor_id
|
25
|
+
session[:spree_visitor_token] ||= SecureRandom.uuid
|
26
|
+
end
|
27
|
+
|
24
28
|
def unsupported_event?(event_name)
|
25
29
|
!Spree::Analytics.events.key?(event_name.to_sym)
|
26
30
|
end
|
@@ -33,7 +33,7 @@ module Spree
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def checkout_started?
|
36
|
-
@order.state == 'address' && @order.state_was == 'cart'
|
36
|
+
(@order.state == 'address' && @order.state_was == 'cart') || (@order.state == 'cart' && correct_state == 'address')
|
37
37
|
end
|
38
38
|
|
39
39
|
def already_have_an_account?
|
@@ -92,7 +92,7 @@ module Spree
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def storefront_products_for_taxon_filters
|
95
|
-
@storefront_products_for_taxon_filters ||= products_for_filters_scope(except_filters: [:taxons])
|
95
|
+
@storefront_products_for_taxon_filters ||= products_for_filters_scope(except_filters: [:taxons, :taxonomy_ids])
|
96
96
|
end
|
97
97
|
|
98
98
|
def filter_taxon_ids
|
@@ -1,5 +1,13 @@
|
|
1
1
|
module Spree
|
2
2
|
module PageHelper
|
3
|
+
# Renders the page with the current theme (or theme preview) and page preview if it exists.
|
4
|
+
# It fetches all page sections and renders them one by one in the order they are set in the page builder by store staff.
|
5
|
+
# It also handles lazy loading of sections.
|
6
|
+
#
|
7
|
+
# @param page [Spree::Page] the page to render
|
8
|
+
# @param variables [Hash] variables to pass to the page sections
|
9
|
+
# @option variables [Array] :pickup_locations ([]) the pickup locations to pass to the page sections
|
10
|
+
# @return [String] the rendered page
|
3
11
|
def render_page(page = nil, variables = {})
|
4
12
|
page ||= current_page
|
5
13
|
|
@@ -11,6 +19,12 @@ module Spree
|
|
11
19
|
"<main class='page-contents'>#{sections_html}</main>".html_safe
|
12
20
|
end
|
13
21
|
|
22
|
+
# Renders a single section of the page.
|
23
|
+
#
|
24
|
+
# @param section [Spree::PageSection] the section to render
|
25
|
+
# @param variables [Hash] variables to pass to the section
|
26
|
+
# @option variables [Boolean] :lazy_allowed (true) whether lazy loading is allowed for the section (if it supports it)
|
27
|
+
# @return [String] the rendered section
|
14
28
|
def render_section(section, variables = {}, lazy_allowed: true)
|
15
29
|
return '' if section.blank?
|
16
30
|
|
@@ -54,6 +68,7 @@ module Spree
|
|
54
68
|
''
|
55
69
|
end
|
56
70
|
|
71
|
+
# Renders a link to the page builder for the given link.
|
57
72
|
def page_builder_link_to(link, options = {}, &block)
|
58
73
|
if link.present?
|
59
74
|
link_to(spree_storefront_resource_url(link.linkable || link), options.except(:label)) do
|
@@ -21,11 +21,15 @@ module Spree
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def weeks_online(product)
|
24
|
+
Spree::Deprecation.warn('weeks_online is deprecated and will be removed in Spree 5.2')
|
25
|
+
|
24
26
|
(Time.current - product.activated_at.in_time_zone(current_store.preferred_timezone)).seconds.in_weeks.to_i.abs
|
25
27
|
end
|
26
28
|
|
27
29
|
def brand_name(product)
|
28
|
-
|
30
|
+
Spree::Deprecation.warn('brand_name is deprecated and will be removed in Spree 5.2. Please use `product.brand_name` instead.')
|
31
|
+
|
32
|
+
product.brand&.name || product.try(:vendor)&.display_name
|
29
33
|
end
|
30
34
|
|
31
35
|
def product_not_selected_options(product, selected_variant, options_param_name: :options)
|
@@ -152,6 +156,10 @@ module Spree
|
|
152
156
|
product.main_taxon.self_and_ancestors.find_all { |taxon| taxon.depth != 0 }
|
153
157
|
end
|
154
158
|
|
159
|
+
# Generates the JSON-LD elements for a list of products.
|
160
|
+
#
|
161
|
+
# @param product_slugs [Array<String>] The slugs of the products to generate elements for
|
162
|
+
# @return [Array<Hash>] The JSON-LD elements
|
155
163
|
def product_list_json_ld_elements(product_slugs)
|
156
164
|
product_slugs.each_with_index.map do |product_slug, index|
|
157
165
|
{
|
@@ -162,6 +170,10 @@ module Spree
|
|
162
170
|
end
|
163
171
|
end
|
164
172
|
|
173
|
+
# Generates the JSON-LD breadcrumbs for a product.
|
174
|
+
#
|
175
|
+
# @param product [Spree::Product] The product to generate breadcrumbs for
|
176
|
+
# @return [Hash] The JSON-LD breadcrumbs
|
165
177
|
def product_json_ld_breadcrumbs(product)
|
166
178
|
json_ld = {
|
167
179
|
'@context' => 'https://schema.org',
|
@@ -3,12 +3,20 @@ module Spree
|
|
3
3
|
include BaseHelper
|
4
4
|
include Heroicon::Engine.helpers
|
5
5
|
|
6
|
+
# Renders the storefront partials for the given section.
|
7
|
+
#
|
8
|
+
# @param section [String] The section to render
|
9
|
+
# @param options [Hash] The options/variables to pass to the partials
|
10
|
+
# @return [String] The rendered partials
|
6
11
|
def render_storefront_partials(section, options = {})
|
7
12
|
Rails.application.config.spree_storefront.send(section).map do |partial|
|
8
13
|
render partial, options
|
9
14
|
end.join.html_safe
|
10
15
|
end
|
11
16
|
|
17
|
+
# Returns the page description for the current page.
|
18
|
+
#
|
19
|
+
# @return [String] The page description
|
12
20
|
def page_description
|
13
21
|
return @page_description if @page_description.present?
|
14
22
|
|
@@ -23,6 +31,10 @@ module Spree
|
|
23
31
|
@page_description
|
24
32
|
end
|
25
33
|
|
34
|
+
# Returns the page image for the current page.
|
35
|
+
# This is used for SEO, social media and Open Graph tags.
|
36
|
+
#
|
37
|
+
# @return [String] The page image
|
26
38
|
def page_image
|
27
39
|
return @page_image if @page_image.present?
|
28
40
|
|
@@ -1,9 +1,16 @@
|
|
1
1
|
module Spree
|
2
2
|
module ThemeHelper
|
3
|
+
# Returns the current page, if not found it will fallback to the homepage
|
4
|
+
#
|
5
|
+
# @return [Spree::Page] the current page
|
3
6
|
def current_page
|
4
7
|
@current_page ||= current_theme.pages.find_by(type: 'Spree::Pages::Homepage')
|
5
8
|
end
|
6
9
|
|
10
|
+
# Returns the current theme, if not found it will fallback to the default theme
|
11
|
+
# If `theme_id` is provided in the params, it will return the theme with the given id
|
12
|
+
#
|
13
|
+
# @return [Spree::Theme] the current theme
|
7
14
|
def current_theme
|
8
15
|
@current_theme ||= if params[:theme_id].present?
|
9
16
|
current_store.themes.find_by(id: params[:theme_id])
|
@@ -14,34 +21,56 @@ module Spree
|
|
14
21
|
@current_theme ||= current_store.themes.first
|
15
22
|
end
|
16
23
|
|
24
|
+
# Returns the current theme preview
|
25
|
+
#
|
26
|
+
# @return [Spree::ThemePreview] the current theme preview
|
17
27
|
def current_theme_preview
|
18
28
|
return if params[:theme_preview_id].blank?
|
19
29
|
|
20
30
|
@current_theme_preview ||= current_theme.previews.find_by(id: params[:theme_preview_id])
|
21
31
|
end
|
22
32
|
|
33
|
+
# Returns the current page preview
|
34
|
+
#
|
35
|
+
# @return [Spree::PagePreview] the current page preview
|
23
36
|
def current_page_preview
|
24
37
|
return if params[:page_preview_id].blank?
|
25
38
|
|
26
39
|
@current_page_preview ||= current_page.previews.find_by(id: params[:page_preview_id])
|
27
40
|
end
|
28
41
|
|
42
|
+
# Returns the current page or page preview, preview takes priority
|
43
|
+
#
|
44
|
+
# @return [Spree::Page] the current page or page preview
|
29
45
|
def current_page_or_preview
|
30
46
|
@current_page_or_preview ||= current_page_preview || current_page
|
31
47
|
end
|
32
48
|
|
49
|
+
# Returns the current theme or theme preview, preview takes priority
|
50
|
+
#
|
51
|
+
# @return [Spree::Theme] the current theme or theme preview
|
33
52
|
def current_theme_or_preview
|
34
53
|
@current_theme_or_preview ||= current_theme_preview || current_theme
|
35
54
|
end
|
36
55
|
|
56
|
+
# Returns the logo set in the `Spree::PageSections::Header` section
|
57
|
+
#
|
58
|
+
# @return [ActiveStorage::Attachment] the logo
|
37
59
|
def current_header_logo
|
38
60
|
@current_header_logo ||= current_theme_or_preview.sections.find_by(type: 'Spree::PageSections::Header')&.logo
|
39
61
|
end
|
40
62
|
|
63
|
+
# Returns whether the page builder is enabled
|
64
|
+
# It checks if there is a theme preview or page preview and if the `page_builder` param is set to `true`
|
65
|
+
#
|
66
|
+
# @return [Boolean] whether the page builder is enabled
|
41
67
|
def page_builder_enabled?
|
42
68
|
@page_builder_enabled ||= (current_theme_preview.present? || current_page_preview.present?) && params[:page_builder] == 'true'
|
43
69
|
end
|
44
70
|
|
71
|
+
# Returns the theme layout sections, eg. header, footer, etc.
|
72
|
+
#
|
73
|
+
# @return [Hash] the theme layout sections
|
45
74
|
def theme_layout_sections
|
46
75
|
@theme_layout_sections ||= current_theme_or_preview.sections.includes(:links, { asset_attachment: :blob },
|
47
76
|
{ blocks: [:rich_text_text, :links] }).all.each_with_object({}) do |section, hash|
|
@@ -55,6 +84,11 @@ module Spree
|
|
55
84
|
{}
|
56
85
|
end
|
57
86
|
|
87
|
+
# Returns the theme setting for the given name
|
88
|
+
# if preview is present, it will return the preview setting, otherwise it will return the theme setting
|
89
|
+
#
|
90
|
+
# @param name [String] the name of the theme setting
|
91
|
+
# @return [String] the theme setting
|
58
92
|
def theme_setting(name)
|
59
93
|
if current_theme_preview.present?
|
60
94
|
current_theme_preview.preferences.with_indifferent_access[name]
|
@@ -64,6 +98,9 @@ module Spree
|
|
64
98
|
end
|
65
99
|
|
66
100
|
# This helper allows us to specify opacity in Tailwind's color palette
|
101
|
+
#
|
102
|
+
# @param name [String] the name of the theme setting
|
103
|
+
# @return [String] the theme setting
|
67
104
|
def theme_setting_rgb_components(name)
|
68
105
|
hex_color = theme_setting(name)
|
69
106
|
return unless hex_color.present?
|
@@ -73,6 +110,10 @@ module Spree
|
|
73
110
|
end
|
74
111
|
|
75
112
|
# https://makandracards.com/makandra/496431-ruby-how-to-convert-hex-color-codes-to-rgb-or-rgba
|
113
|
+
# Converts a hex color to rgb
|
114
|
+
#
|
115
|
+
# @param hex [String] the hex color
|
116
|
+
# @return [String] the rgb color
|
76
117
|
def hex_color_to_rgb(hex)
|
77
118
|
return unless hex.present?
|
78
119
|
|
@@ -80,6 +121,10 @@ module Spree
|
|
80
121
|
"rgb(#{rgb.join(', ')})"
|
81
122
|
end
|
82
123
|
|
124
|
+
# Converts a hex color to rgba
|
125
|
+
#
|
126
|
+
# @param hex [String] the hex color
|
127
|
+
# @return [String] the rgba color
|
83
128
|
def hex_color_to_rgba(hex)
|
84
129
|
return unless hex.present?
|
85
130
|
|
@@ -88,6 +133,10 @@ module Spree
|
|
88
133
|
"rgba(#{rgb.join(', ')}, #{opacity.round(2)})"
|
89
134
|
end
|
90
135
|
|
136
|
+
# Returns the section inline CSS styles
|
137
|
+
#
|
138
|
+
# @param section [Spree::PageSection] the section
|
139
|
+
# @return [String] the section inline CSS styles
|
91
140
|
def section_styles(section)
|
92
141
|
styles = {}
|
93
142
|
|
@@ -116,6 +165,10 @@ module Spree
|
|
116
165
|
styles.map { |k, v| "#{k}: #{v}" }.join(';')
|
117
166
|
end
|
118
167
|
|
168
|
+
# Returns the section heading inline CSS styles
|
169
|
+
#
|
170
|
+
# @param section [Spree::PageSection] the section
|
171
|
+
# @return [String] the section heading inline CSS styles
|
119
172
|
def section_heading_styles(section)
|
120
173
|
styles = {}
|
121
174
|
|
@@ -128,6 +181,11 @@ module Spree
|
|
128
181
|
styles.compact_blank.map { |k, v| "#{k}: #{v}" }.join(';')
|
129
182
|
end
|
130
183
|
|
184
|
+
# Returns the block HTML attributes
|
185
|
+
# it automatically adds data attributes for page builder
|
186
|
+
#
|
187
|
+
# @param block [Spree::PageBlock] the block
|
188
|
+
# @return [Hash] the block attributes
|
131
189
|
def block_attributes(block, allowed_styles: :all)
|
132
190
|
has_width_desktop = block.respond_to?(:preferred_width_desktop) && block.preferred_width_desktop.present? ? "width-desktop='true'" : nil
|
133
191
|
|
@@ -147,6 +205,11 @@ module Spree
|
|
147
205
|
tag.attributes(attributes)
|
148
206
|
end
|
149
207
|
|
208
|
+
# Returns the link HTML attributes
|
209
|
+
# it automatically adds data attributes for page builder
|
210
|
+
#
|
211
|
+
# @param link [Spree::PageLink] the link
|
212
|
+
# @return [Hash] the link attributes
|
150
213
|
def link_attributes(link, as_html: true)
|
151
214
|
parent_type = case link.parent_type
|
152
215
|
when 'Spree::PageSection'
|
@@ -184,6 +247,11 @@ module Spree
|
|
184
247
|
end
|
185
248
|
end
|
186
249
|
|
250
|
+
# Returns the block inline CSS styles
|
251
|
+
#
|
252
|
+
# @param block [Spree::PageBlock] the block
|
253
|
+
# @param allowed_styles [Symbol] the allowed styles, if not provided, all styles will be returned
|
254
|
+
# @return [String] the block inline CSS styles
|
187
255
|
def block_styles(block, allowed_styles: :all)
|
188
256
|
styles = {}
|
189
257
|
|
@@ -229,12 +297,20 @@ module Spree
|
|
229
297
|
styles.map { |k, v| "#{k}: #{v}" }.join(';')
|
230
298
|
end
|
231
299
|
|
300
|
+
# Returns the block background color style
|
301
|
+
#
|
302
|
+
# @param block [Spree::PageBlock] the block
|
303
|
+
# @return [String] the block background color style
|
232
304
|
def block_background_color_style(block)
|
233
305
|
return nil unless block.respond_to?(:preferred_background_color) && block.preferred_background_color.present?
|
234
306
|
|
235
307
|
"background-color: #{block.preferred_background_color};"
|
236
308
|
end
|
237
309
|
|
310
|
+
# Returns the block CSS classes
|
311
|
+
#
|
312
|
+
# @param block [Spree::PageBlock] the block
|
313
|
+
# @return [String] the block CSS classes
|
238
314
|
def block_css_classes(block)
|
239
315
|
classes = []
|
240
316
|
classes << "justify-#{block.preferred_justify}" if block.respond_to?(:preferred_justify) && block.preferred_justify.present?
|