Reputation: 464
I have a spree site where there are multiple different user roles. Some categories of products are only available to certain users (eg. Wholesale customers can access wholesale products). How would I limit this? I tried to do it using
<% if spree_current_user.has_spree_role?("wholesale") %>
<% @products = Spree::Product.find_by_sql('SELECT sp.* FROM spree_products sp LEFT JOIN spree_products_taxons spt ON spt.product_id = sp.id LEFT JOIN spree_taxons st ON spt.taxon_id = st.id WHERE st.name = "Wholesale"') %>
in the products partial where it shows the products but this overrides the retrieve_products method so it needs to be done somewhere earlier. I tried it in the /lib/spree/core/search/base.rb retrieve_products but this doesn't recognize spree_current_user...
Sorry for being a noob. Any tips would be much appreciated.
Upvotes: 0
Views: 95
Reputation: 4615
Firstly you must create extension
After under your extension create /controllers/spree/home_controller_decorator.rb
In this file put:
module Spree
HomeController.class_eval do
def index
@retrieve_prodcuts = # type here your @products code
end
end
end
Similarly you can do this also for products_controller
or other controllers.
Upvotes: 1