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.

Improve performance of `Product#for_store` scope (#11516)

Damian Legawiec4b7f668222e3
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 17031fcb74..35f8a6ce90 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -120,6 +120,8 @@ module Spree
validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: true, scope: spree_base_uniqueness_scope }
validate :discontinue_on_must_be_later_than_available_on, if: -> { available_on && discontinue_on }
+ scope :for_store, ->(store) { joins(:store_products).where(StoreProduct.table_name => { store_id: store.id }) }
+
attr_accessor :option_values_hash
accepts_nested_attributes_for :product_properties, allow_destroy: true, reject_if: ->(pp) { pp[:property_name].blank? }