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.

Fix `Spree::Variant.eligible` so it works without using numeric IDs (#12207)

Damian Kaczmarczyke55edff3f3c6
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 5ff8f2d785..0d246b4810 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -76,13 +76,10 @@ module Spree
scope :eligible, -> {
where(is_master: false).or(
where(
- <<-SQL
- #{Variant.quoted_table_name}.id IN (
- SELECT MIN(#{Variant.quoted_table_name}.id) FROM #{Variant.quoted_table_name}
- GROUP BY #{Variant.quoted_table_name}.product_id
- HAVING COUNT(*) = 1
- )
- SQL
+ product_id: Spree::Variant.
+ select(:product_id).
+ group(:product_id).
+ having("COUNT(#{Spree::Variant.table_name}.id) = 1")
)
)
}