Developer forum

Forum » Development » Product check anonymous assortment

Product check anonymous assortment

John Broers
Reply

Hi,


Is there a way to check if a product is available for an anonymous user when working with assortments? We are using the method GetProductById with the assortment parameter set to true. This seems to work for authenticated users, it returns null when a product is not available for the user. But for anonymous users it's always giving back the product. Digging deeper into this method we found an internal method HasAccessToProduct. That sounds very usefull. Is there anything similar like that public available?


BR,

John Broers


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi John

When you use GetProductById there is a check for assortments, but only for logged in users. That is an explicit test made inside that call chain.

Anonymous assortments support was added later and this particular method call does not take that into account - so that is probably a bug. We need to look into how to fix so we do not break stuff on the way.

What you can do as a workaround right now is to call Dynamicweb.Ecommerce.Services.Assortments.HasAccessToProduct(product, null) if a user is not logged in - and that will tell you weather the product is insde an anoymous assortment

Votes for this answer: 1

 

You must be logged in to post in the forum