I have been given a requirement that I have not seen posted before, forgive me if I missed it. The standard access control list for products limits being able to see the product in the catalog by role. While this functionality is great, and we use it regularly, we also require a way to allow customers to buy a product only if they are in a certain role, but other roles can still view the product. What would be the best way to go about this? Simply create a plugin that checks the customer and the product to see if the add to cart button should be visible?
We created a new class and inherited from IProductService and then override the standard methods (GetProductById, etc). We first called the base method and then depending on the business logic set the DisableBuyButton (on the product record) to true or false.
methods are the ones called to display the product details page and list of products respectively? Thus overriding them and changing the disable buy button flag based on the customer should remove the option to buy? If so that is amazing and I appreciate the direction!
We created a new class and inherited from IProductService and then override the standard methods (GetProductById, etc). We first called the base method and then depending on the business logic set the DisableBuyButton (on the product record) to true or false.
Hope that helps
So I completed this implementation and it works like a charm for quick view and the product details view. However, in the grid or list view it is hit or miss. Did you seem to have a problem with caching or something of that nature?
Something rings a bell that we did but i can't see anything in the code that relates to caching. It looks like we also override : GetAllProductsDisplayedOnHomePage() SearchProducts()
Also a gotcha for us was when amending records in the admin area the class would get called and certain products would randomly get bits changed (we use the same method to override prices).
Anyway we got round it by adding the following when overriding the methods.
//Get the product record var productRecord = base.GetProductById(productId);
if (_workContext.IsAdmin) { return productRecord; }
Something rings a bell that we did but i can't see anything in the code that relates to caching. It looks like we also override : GetAllProductsDisplayedOnHomePage() SearchProducts()
Also a gotcha for us was when amending records in the admin area the class would get called and certain products would randomly get bits changed (we use the same method to override prices).
Anyway we got round it by adding the following when overriding the methods.
//Get the product record var productRecord = base.GetProductById(productId);
if (_workContext.IsAdmin) { return productRecord; }
Something definitely seems off. After waiting all night, I did another reload and while in the product list/grid view, the buy button is not disabled, but while in the quick view and product details view all is well. I will see what I can figure out. I definitely noticed that gotcha though. I was wondering why my products had the buy button disabled when I was a member of the role allowed to purchase them. Well, the admin area had the disable buy button checkbox toggled and I clicked save. That was a fun fix. Thank you for your help!