Discussions

Conditionally show/hide collections with Commerce Kickstart

Hi all,

since some days I am trying to hide some collections from people who are not logged in as authenticated users. Or in other words: Some collections should only be visible to people who have at least the role "Authenticated User". I already added a field "authenticated users only" to the taxonomy vocabulary "collection".

The problem is that I couldn't find a way how to filter the items that are being shown to the users.

I tried multiple ways like the module "content_access", plugins like "views_plugin_access" or just hooks like "hook_node_access".

"content_access" seems to be the wrong way.
With the views plugins, I don't know how to get the data of the current node and its collection vocabulary.

I would be very thankful if anyone could put me in the right direction. I am using the current release of Commerce Cickstart.

Thank you in advance

Ruediger Hahn

Posted: May 10, 2016

Comments

Ruediger Hahn on June 22, 2016

Hi,

I still couldn't solve this problem. I think I should use a combination of the api function "user_is_logged_in" and a hook from search_api_views. I could add a new condition to the query using the hook search_api_views_query_alter, where I would check if the product's current collection should only be accessible to authenticated users. As I mentionend before I already added a custom field "authenticated_users_only" to the taxonomy vocabulary "collection". I just do not know how to access this field from inside the search_api_views_query_alter hook to create an additional condition.

Can anybody help me please?

Thank you in advance

Ruediger