Sha256: e37bfc34ac48483fe742a492b6041af1c61bb9bc00b58b51246baa7ae230eabf

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Spree
  module StoreHelper
    include LocaleHelper

    def store_country_iso(store = nil)
      store ||= current_store if defined?(current_store)

      store&.default_country&.iso&.downcase
    end

    def stores
      @stores ||= Spree::Store.includes(:default_country).order(:id)
    end

    def store_currency_symbol(store = nil)
      store ||= current_store  if defined?(current_store)
      return unless store&.default_currency

      ::Money::Currency.find(store.default_currency).symbol
    end

    def store_locale_name(store = nil)
      store ||= current_store if defined?(current_store)
      return unless store
      return store.name if store.default_locale.blank?

      locale_full_name(store.default_locale)
    end

    def should_render_store_chooser?
      Spree::Frontend::Config[:show_store_selector] && stores.size > 1
    end

    def store_link(store = nil, html_opts = {})
      store ||= current_store if defined?(current_store)
      return unless store

      link_to "#{store_locale_name(store)} (#{store_currency_symbol(store)})", store.formatted_url, **html_opts
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_frontend-4.7.0 app/helpers/spree/store_helper.rb
spree_frontend-4.6.0 app/helpers/spree/store_helper.rb
spree_frontend-4.5.0 app/helpers/spree/store_helper.rb
spree_frontend-4.4.0 app/helpers/spree/store_helper.rb