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.

Storefront Api for store

Prabin Poudel17bdccb681ad
diff --git a/api/app/controllers/spree/api/v2/storefront/stores_controller.rb b/api/app/controllers/spree/api/v2/storefront/stores_controller.rb
index c7f3d98504..d499c872b1 100644
--- a/api/app/controllers/spree/api/v2/storefront/stores_controller.rb
+++ b/api/app/controllers/spree/api/v2/storefront/stores_controller.rb
@@ -9,8 +9,12 @@ module Spree
private
+ def scope
+ Spree::Store.accessible_by(current_ability, :show)
+ end
+
def resource
- Spree::Store.find_by(params[:id])
+ scope.find_by!(code: params[:code])
end
def resource_serializer
diff --git a/api/config/routes.rb b/api/config/routes.rb
index ae9e5800cb..95caf4397e 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -161,7 +161,7 @@ Spree::Core::Engine.add_routes do
get '/order_status/:number', to: 'order_status#show', as: :order_status
resources :products, only: %i[index show]
resources :taxons, only: %i[index show], id: /.+/
- resources :stores, only: %i[show]
+ get '/stores/:code', to: 'stores#show', as: :store
end
end
diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb
index 9c4b7af9f3..29d83e0cfa 100644
--- a/core/app/models/spree/ability.rb
+++ b/core/app/models/spree/ability.rb
@@ -59,6 +59,7 @@ module Spree
can :read, Taxonomy
can :read, Variant
can :read, Zone
+ can :read, Store
end
# Include any abilities registered by extensions, etc.