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.

[EN-462] Fixes admin panel bug with stores field on product form

Robert Nowakowski821b21f46c75
diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rb
index 151ced70af..3b1295c2f6 100644
--- a/backend/app/controllers/spree/admin/stores_controller.rb
+++ b/backend/app/controllers/spree/admin/stores_controller.rb
@@ -15,7 +15,31 @@ module Spree
helper_method :all_locales_options
def index
- @stores = Spree::Store.all
+ if params[:ids]
+ load_stores_by_ids
+ elsif params[:q]
+ load_stores_by_query
+ else
+ @stores = Spree::Store.all
+ end
+
+ respond_with(@stores) do |format|
+ format.json { render layout: false }
+ end
+ end
+
+ def load_stores_by_ids
+ ids = params[:ids].split(',')
+ @stores = Spree::Store.where(id: ids)
+ end
+
+ def load_stores_by_query
+ @stores = if defined?(SpreeGlobalize)
+ Spree::Store.joins(:translations).where("LOWER(#{Store::Translation.table_name}.name) LIKE LOWER(:query)",
+ query: "%#{params[:q]}%")
+ else
+ Spree::Store.where('LOWER(name) LIKE LOWER(:query)', query: params[:q].to_s)
+ end
end
def create