Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Add taxonomy permalink to translated taxon permalinks

Rafal Cymerys56a01ec35c0c
diff --git a/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb b/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb
index 69ea5c7540..f01420fbac 100644
--- a/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb
+++ b/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb
@@ -227,8 +227,8 @@ describe 'Taxons Spec', type: :request do
let(:expected_slugs) do
{
en: 'categories/test_slug_en',
- pl: 'test_slug_pl',
- es: 'test_slug_es'
+ pl: 'categories/test_slug_pl',
+ es: 'categories/test_slug_es'
}
end
diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb
index bafd4a70e8..1db62636b5 100644
--- a/core/app/models/spree/taxon.rb
+++ b/core/app/models/spree/taxon.rb
@@ -61,6 +61,17 @@ module Spree
self::Translation.class_eval do
alias_attribute :slug, :permalink
+
+ before_create :set_permalink
+
+ def set_permalink
+ parent = translated_model.parent
+ if parent.present?
+ self.permalink = [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last)].join('/')
+ else
+ self.permalink = name.to_url if permalink.blank?
+ end
+ end
end
# indicate which filters should be used for a taxon
@@ -82,11 +93,7 @@ module Spree
# Creates permalink base for friendly_id
def set_permalink
- if parent.present?
- self.permalink = [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last)].join('/')
- else
- self.permalink = name.to_url if permalink.blank?
- end
+ translations.each(&:set_permalink)
end
def active_products
diff --git a/core/spec/models/spree/taxon_spec.rb b/core/spec/models/spree/taxon_spec.rb
index a8d31175da..878308e2c6 100644
--- a/core/spec/models/spree/taxon_spec.rb
+++ b/core/spec/models/spree/taxon_spec.rb
@@ -198,8 +198,8 @@ describe Spree::Taxon, type: :model do
let(:expected_slugs) do
{
'en' => 'categories/test_slug_en',
- 'fr' => 'test_slug_fr',
- 'pl' => 'test_slug_pl'
+ 'fr' => 'categories/test_slug_fr',
+ 'pl' => 'categories/test_slug_pl'
}
end
@@ -212,8 +212,8 @@ describe Spree::Taxon, type: :model do
let(:expected_slugs) do
{
'en' => 'categories/test_slug_en',
- 'fr' => 'test_slug_fr',
- 'pl' => 'test_slug_fr'
+ 'fr' => 'categories/test_slug_fr',
+ 'pl' => 'categories/test_slug_fr'
}
end