Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added StoreHelper#store_link
Damian Legawiec2083f87b3dbb
diff --git a/frontend/app/helpers/spree/store_helper.rb b/frontend/app/helpers/spree/store_helper.rbindex 76be480c3c..6e3bab088c 100644--- a/frontend/app/helpers/spree/store_helper.rb+++ b/frontend/app/helpers/spree/store_helper.rb@@ -1,27 +1,24 @@module Spreemodule StoreHelper- def store_country_iso(store)- store ||= current_store- return unless store- return unless store.default_country+ def store_country_iso(store = nil)+ store ||= current_store if defined?(current_store)- store.default_country.iso.downcase+ store&.default_country&.iso&.downcaseenddef stores@stores ||= Spree::Store.includes(:default_country).order(:id)end- def store_currency_symbol(store)- store ||= current_store- return unless store- return unless store.default_currency+ def store_currency_symbol(store = nil)+ store ||= current_store if defined?(current_store)+ return unless store&.default_currency::Money::Currency.find(store.default_currency).symbolend- def store_locale_name(store)- store ||= current_store+ def store_locale_name(store = nil)+ store ||= current_store if defined?(current_store)return unless storereturn store.name if store.default_locale.blank?@@ -31,5 +28,12 @@ module Spreedef should_render_store_chooser?Spree::Config.show_store_selector && stores.size > 1end++ 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+ endendenddiff --git a/frontend/spec/helpers/store_helper_spec.rb b/frontend/spec/helpers/store_helper_spec.rbindex 158129c79b..7198ba3925 100644--- a/frontend/spec/helpers/store_helper_spec.rb+++ b/frontend/spec/helpers/store_helper_spec.rb@@ -2,8 +2,8 @@ require 'spec_helper'module Spreedescribe StoreHelper, type: :helper do- let(:germany) { create(:country, name: 'Germany', iso: 'GR') }- let(:eu_store) { create(:store, default_currency: 'EUR', default_locale: 'de', default_country: germany) }+ let(:germany) { build(:country, name: 'Germany', iso: 'GR') }+ let(:eu_store) { build(:store, url: 'eu.spreecommerce.org', default_currency: 'EUR', default_locale: 'de', default_country: germany) }before doI18n.backend.store_translations(:de,@@ -26,16 +26,25 @@ module Spreeit { expect(store_country_iso(eu_store)).to eq('gr') }it { expect(store_country_iso(Spree::Store.default)).to be_nil }+ it { expect { store_country_iso(nil) }.not_to raise_error }enddescribe '#store_currency_symbol' doit { expect(store_currency_symbol(Spree::Store.default)).to eq('$') }it { expect(store_currency_symbol(eu_store)).to eq('€') }+ it { expect { store_currency_symbol(nil) }.not_to raise_error }enddescribe '#store_locale_name' doit { expect(store_locale_name(Spree::Store.default)).to eq('English (US)') }it { expect(store_locale_name(eu_store)).to eq('Deutsch (DE)') }+ it { expect { store_locale_name(nil) }.not_to raise_error }+ end++ describe '#store_link' do+ it { expect(store_link(eu_store)).to eq('<a href="https://eu.spreecommerce.org">Deutsch (DE) (€)</a>') }+ it { expect(store_link(eu_store, class: 'some-class')).to eq('<a class="some-class" href="https://eu.spreecommerce.org">Deutsch (DE) (€)</a>') }+ it { expect { store_link(nil) }.not_to raise_error }enddescribe '#should_render_store_chooser?' do