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.

WIP Admin products scoped by current store

Damian Kaczmarczyk1e2f06f27d72
diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb
index 415b61233c..a0cca5d328 100644
--- a/backend/app/controllers/spree/admin/products_controller.rb
+++ b/backend/app/controllers/spree/admin/products_controller.rb
@@ -31,7 +31,13 @@ module Spree
invoke_callbacks(:update, :after)
flash[:success] = flash_message_for(@object, :successfully_updated)
respond_with(@object) do |format|
- format.html { redirect_to location_after_save }
+ format.html do
+ if params[:product][:store_ids].include? current_store.id
+ redirect_to location_after_save
+ else
+ redirect_to admin_products_url
+ end
+ end
format.js { render layout: false }
end
else
@@ -91,8 +97,12 @@ module Spree
protected
+ def scope
+ current_store.products
+ end
+
def find_resource
- Product.with_deleted.friendly.find(params[:id])
+ scope.with_deleted.friendly.find(params[:id])
end
def location_after_save
@@ -114,7 +124,7 @@ module Spree
params[:q][:not_discontinued] ||= '1'
params[:q][:s] ||= 'name asc'
- @collection = super
+ @collection = scope
# Don't delete params[:q][:deleted_at_null] here because it is used in view to check the
# checkbox for 'q[deleted_at_null]'. This also messed with pagination when deleted_at_null is checked.
if params[:q][:deleted_at_null] == '0'