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
Fix `store#formatted_url` when app is on production env (#12532)
Damian Kaczmarczykc9f20b6e96e8
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex ffb16d88db..5b919414dc 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -263,25 +263,29 @@ module Spreeenddef formatted_url- @formatted_url ||= if Rails.env.development? || Rails.env.test?- scheme = Rails.application.routes.default_url_options[:protocol] || :http- port = Rails.application.routes.default_url_options[:port].presence || (Rails.env.development? ? 3000 : nil)+ @formatted_url ||= beginclean_url = url.to_s.sub(%r{^https?://}, '').split(':').first- if scheme.to_sym == :https- URI::HTTPS.build(- host: clean_url,- port: port- ).to_s++ if Rails.env.development? || Rails.env.test?+ scheme = Rails.application.routes.default_url_options[:protocol] || :http+ port = Rails.application.routes.default_url_options[:port].presence || (Rails.env.development? ? 3000 : nil)++ if scheme.to_sym == :https+ URI::HTTPS.build(+ host: clean_url,+ port: port+ ).to_s+ else+ URI::HTTP.build(+ host: clean_url,+ port: port+ ).to_s+ endelse- URI::HTTP.build(- host: clean_url,- port: port+ URI::HTTPS.build(+ host: clean_url).to_send- else- URI::HTTPS.build(- host: clean_url- ).to_sendenddiff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rbindex 4d6ace3af9..f0d986cd8e 100644--- a/core/spec/models/spree/store_spec.rb+++ b/core/spec/models/spree/store_spec.rb@@ -794,6 +794,12 @@ describe Spree::Store, type: :model doit { expect(store.formatted_url).to eq('http://localhost:3000') }end++ context 'on production' do+ before { allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production')) }++ it { expect(store.formatted_url).to eq('https://mystore.mydomain.dev') }+ endenddescribe '#formatted_url_or_custom_domain' do