Module: Spree::StorefrontHelper

Includes:
BaseHelper, ImagesHelper, ShipmentHelper
Included in:
SeoController, StoreController, TaxonsController
Defined in:
app/helpers/spree/storefront_helper.rb

Instance Method Summary collapse

Instance Method Details

#as_aspect_ratio(attachment) ⇒ Object



82
83
84
85
# File 'app/helpers/spree/storefront_helper.rb', line 82

def as_aspect_ratio(attachment)
  Spree::Deprecation.warn('as_aspect_ratio is deprecated. Please use spree_asset_aspect_ratio instead.')
  spree_asset_aspect_ratio(attachment)
end

#page_descriptionString

Returns the page description for the current page.

Returns:

  • (String)

    The page description



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/spree/storefront_helper.rb', line 41

def page_description
  return @page_description if @page_description.present?

  @page_description = object.meta_description if object.respond_to?(:meta_description)

  if @page_description.blank? && [Spree::Product, Spree::Taxon, Spree::Post].include?(object.class)
    @page_description = truncate(strip_tags(object.description.to_s).strip, length: 160, separator: ' ', escape: false)
  end

  @page_description = current_store.meta_description if @page_description.blank?

  @page_description
end

#page_imageString

Returns the page image for the current page. This is used for SEO, social media and Open Graph tags.

Returns:

  • (String)

    The page image



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/spree/storefront_helper.rb', line 59

def page_image
  return @page_image if @page_image.present?

  if object.is_a? Spree::Product
    @page_image = object.default_image&.attachment
  elsif object.respond_to?(:image)
    @page_image = object.image
  end

  @page_image ||= current_store.social_image

  @page_image
end

#paths_equal?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
# File 'app/helpers/spree/storefront_helper.rb', line 108

def paths_equal?(path1, path2)
  path1 = URI.parse(path1).path.chomp('/')
  path2 = URI.parse(path2).path.chomp('/')

  path1 == path2
end

#render_storefront_partials(section, options = {}) ⇒ String

Renders the storefront partials for the given section.

Parameters:

  • section (String)

    The section to render

  • options (Hash) (defaults to: {})

    The options/variables to pass to the partials

Returns:

  • (String)

    The rendered partials



32
33
34
35
36
# File 'app/helpers/spree/storefront_helper.rb', line 32

def render_storefront_partials(section, options = {})
  Spree.storefront.partials.send(section.to_s.gsub('_partials', '').to_sym).map do |partial|
    render partial, options
  end.join.html_safe
end

#show_account_pane?Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
# File 'app/helpers/spree/storefront_helper.rb', line 101

def 
  !try_spree_current_user &&
    defined?() && !paths_equal?(canonical_path, ) &&
    defined?() && !paths_equal?(canonical_path, ) &&
    defined?(spree_forgot_password_path) && !paths_equal?(canonical_path, spree_forgot_password_path)
end

#spree_storefront_base_cache_keyArray

Returns the cache key for the storefront including the current wishlist and order.

Returns:

  • (Array)

    The cache key



11
12
13
14
15
16
17
18
# File 'app/helpers/spree/storefront_helper.rb', line 11

def spree_storefront_base_cache_key
  @spree_storefront_base_cache_key ||= [
    spree_base_cache_key,
    current_wishlist,
    current_order,
    Spree::Current.price_lists.cache_key_with_version
  ].compact
end

#spree_storefront_base_cache_scopeProc

Returns the cache scope for the storefront including the current wishlist and order.

Returns:

  • (Proc)

    The cache scope



23
24
25
# File 'app/helpers/spree/storefront_helper.rb', line 23

def spree_storefront_base_cache_scope
  ->(record = nil) { [*spree_storefront_base_cache_key, record].compact_blank }
end

#svg_country_icon(country_code) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/spree/storefront_helper.rb', line 87

def svg_country_icon(country_code)
  language_to_country = {
    'el' => 'gr',
    'en' => 'us',
    'ja' => 'jp',
    'uk' => 'ua'
  }

  normalized_code = country_code.to_s.downcase
  final_country_code = language_to_country.fetch(normalized_code, normalized_code)

  tag.span(class: "fi fi-#{final_country_code}")
end

#tailwind_classes_for(flash_type) ⇒ Object



73
74
75
76
77
78
79
80
# File 'app/helpers/spree/storefront_helper.rb', line 73

def tailwind_classes_for(flash_type)
  {
    notice: 'alert-notice',
    success: 'alert-success',
    error: 'alert-error',
    alert: 'alert-warning',
  }.stringify_keys[flash_type.to_s] || flash_type.to_s
end