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.

Fixed Storefront products list N+1 when loading product brand name (#12747)

Damian Legawiec4c2df742c420
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 1c21074a18..12fed71da1 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -595,7 +595,11 @@ module Spree
join_translation_table(Taxonomy).
find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_brands_name) })
else
- taxons.joins(:taxonomy).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_brands_name) })
+ if taxons.loaded?
+ taxons.find { |taxon| taxon.taxonomy.name == Spree.t(:taxonomy_brands_name) }
+ else
+ taxons.joins(:taxonomy).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_brands_name) })
+ end
end
end
@@ -606,7 +610,11 @@ module Spree
order(depth: :desc).
find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_categories_name) })
else
- taxons.joins(:taxonomy).order(depth: :desc).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_categories_name) })
+ if taxons.loaded?
+ taxons.find { |taxon| taxon.taxonomy.name == Spree.t(:taxonomy_categories_name) }
+ else
+ taxons.joins(:taxonomy).order(depth: :desc).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_categories_name) })
+ end
end
end