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 for_store scope to Spree::Taxon model

Szymon Iwacz85b6f3493916
diff --git a/api/app/serializers/spree/v2/storefront/product_serializer.rb b/api/app/serializers/spree/v2/storefront/product_serializer.rb
index ca9d7fc909..10c8364750 100644
--- a/api/app/serializers/spree/v2/storefront/product_serializer.rb
+++ b/api/app/serializers/spree/v2/storefront/product_serializer.rb
@@ -49,7 +49,7 @@ module Spree
has_many :product_properties
has_many :taxons do |object, params|
- params[:store].taxons.joins(:products).where(products: { id: object.id })
+ object.taxons.for_store(params[:store])
end
# all images from all variants
diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb
index 6f89c14d91..fbdf93ef88 100644
--- a/core/app/models/spree/taxon.rb
+++ b/core/app/models/spree/taxon.rb
@@ -37,6 +37,8 @@ module Spree
has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::TaxonImage'
+ scope :for_store, ->(store) { joins(:taxonomy).where(spree_taxonomies: { store_id: store.id }) }
+
self.whitelisted_ransackable_associations = %w[taxonomy]
# indicate which filters should be used for a taxon