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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added Product#for_user method
Damian Legawiecc60fbb528de0
diff --git a/core/app/models/concerns/spree/product_scopes.rb b/core/app/models/concerns/spree/product_scopes.rbindex f6ca24ef24..0b0152033c 100644--- a/core/app/models/concerns/spree/product_scopes.rb+++ b/core/app/models/concerns/spree/product_scopes.rb@@ -227,6 +227,14 @@ module Spreeendsearch_scopes << :active+ def self.for_user(user = nil)+ if user.try(:has_spree_role?, 'admin')+ with_deleted+ else+ not_deleted.not_discontinued.where("#{Product.quoted_table_name}.available_on <= ?", Time.current)+ end+ end+add_search_scope :taxons_name_eq do |name|group('spree_products.id').joins(:taxons).where(Taxon.arel_table[:name].eq(name))enddiff --git a/frontend/app/controllers/spree/products_controller.rb b/frontend/app/controllers/spree/products_controller.rbindex 7b0d5af0e0..b0b7354b4a 100644--- a/frontend/app/controllers/spree/products_controller.rb+++ b/frontend/app/controllers/spree/products_controller.rb@@ -23,7 +23,7 @@ module Spree@taxon = params[:taxon_id].present? ? Spree::Taxon.find_by(id: params[:taxon_id]) : nil@taxon = @product.taxons.first unless @taxon.present?-+if !http_cache_enabled? || stale?(etag: etag_show, last_modified: last_modified_show, public: true)@product_summary = Spree::ProductSummaryPresenter.new(@product).call@product_properties = @product.product_properties.includes(:property)@@ -52,15 +52,7 @@ module Spreeenddef load_product- @products = if try_spree_current_user.try(:has_spree_role?, 'admin')- Product.with_deleted- else- Product.active(current_currency)- end-- @product = @products.includes(:master).- friendly.- find(params[:id])+ @product = Product.for_user(try_spree_current_user).friendly.find(params[:id])enddef load_taxon