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
add favicon_path attribute to V2::Storefront::StoreSerializer
Łukasz Adamczyk78170d8664b9
diff --git a/api/app/serializers/spree/v2/storefront/store_serializer.rb b/api/app/serializers/spree/v2/storefront/store_serializer.rbindex 8bd8683a89..468da22ba2 100644--- a/api/app/serializers/spree/v2/storefront/store_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/store_serializer.rb@@ -10,6 +10,13 @@ module Spreehas_many :menushas_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id++ attribute :favicon_path do |store|+ if store.favicon_image.attached?+ url_helpers = Rails.application.routes.url_helpers+ url_helpers.rails_representation_path(store.favicon, only_path: true)+ end+ endendendenddiff --git a/api/spec/requests/spree/api/v2/storefront/stores_spec.rb b/api/spec/requests/spree/api/v2/storefront/stores_spec.rbindex 8c49988d00..d84b77f61f 100644--- a/api/spec/requests/spree/api/v2/storefront/stores_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/stores_spec.rb@@ -28,6 +28,20 @@ describe 'Storefront API v2 Stores spec', type: :request doexpect(json_response['data']).to have_relationship(:default_country)expect(json_response['data']).to have_relationship(:default_country).with_data('id' => store.default_country_id.to_s, 'type' => 'country')end++ describe 'favicon_path attribute' do+ context 'with favicon attached' do+ let!(:store) { create(:store, :with_favicon) }++ it 'returns store favicon path' do+ expect(json_response.dig(:data, :attributes, :favicon_path)).to end_with('favicon.ico')+ end+ end++ context 'with no favicon attached' do+ it { expect(json_response['data']).to have_attribute(:favicon_path).with_value(nil) }+ end+ endendcontext 'with invalid code param' dodiff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex 5a478cb62d..5152bfce06 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -60,7 +60,7 @@ module Spreeendend- def favicon_path+ def spree_favicon_pathmain_app.url_for(current_store.favicon || 'favicon.ico')enddiff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rbindex f2ed2915bc..b6c02d2e48 100644--- a/core/spec/helpers/base_helper_spec.rb+++ b/core/spec/helpers/base_helper_spec.rb@@ -327,19 +327,19 @@ describe Spree::BaseHelper, type: :helper doendend- describe '#favicon_path' do+ describe '#spree_favicon_path' docontext 'when a store has its own favicon' dolet(:current_store) { create(:store, :with_favicon) }it do- expect(favicon_path).to end_with('favicon.ico')- expect(URI.parse(favicon_path).host).to be_present+ expect(spree_favicon_path).to end_with('favicon.ico')+ expect(URI.parse(spree_favicon_path).host).to be_presentendendcontext 'when a store has no favicon' doit do- expect(favicon_path).to eq('favicon.ico')+ expect(spree_favicon_path).to eq('favicon.ico')endendenddiff --git a/frontend/app/views/spree/shared/_head.html.erb b/frontend/app/views/spree/shared/_head.html.erbindex b08fa67d5b..5fe3a62629 100644--- a/frontend/app/views/spree/shared/_head.html.erb+++ b/frontend/app/views/spree/shared/_head.html.erb@@ -4,7 +4,7 @@<%== meta_data_tags %><%== meta_robots %><%= canonical_tag(current_store.url) %>-<%= favicon_link_tag(favicon_path) %>+<%= favicon_link_tag(spree_favicon_path) %><%= stylesheet_link_tag 'spree/frontend/all', media: 'screen', 'data-turbolinks-track': 'reload' %><%= csrf_meta_tags %><%= render 'spree/shared/paths' %>