Forums / Developer / Fetching products related to a user

Fetching products related to a user

Author Message

Marat M.

Tuesday 19 July 2005 2:42:41 am

Hi all,

I've added an [Object relation] attribute to my product class. The related object is a user. Thus I can manually specify the user for each product or leave this attribute empty (No relation).

What I want to do is to list products belonging to a current user only.

Unfortunately, I don't know is there a special function to fetch objects related to a user. Can anyone help?

Thanks,
Marat

Marat M.

Tuesday 19 July 2005 4:55:09 am

Oh, I forgot. The section of the site where the products are going to be listed will be available only after logging in. So, the task is to capture the current user and make so that he/she will see only those items, that are related to him/her. Is it possible?

K259

Wednesday 20 July 2005 2:14:34 am

Hi!

Check out the template which lists the users draft (the template which is used in the admin-part under tab: "my drafts").

This template fetches draft produced by the "logged in" user.

Marat M.

Wednesday 20 July 2005 5:06:19 am

I enabled Debug template and captured the template name used in the Admin/MyAccount/Drafts. It is design/admin/templates/content/draft.tpl. But it makes no use for me because the template uses a special function, like this:


{let draft_list=fetch('content','draft_version_list',hash(limit,$page_limit,offset,$view_parameters.offset))}
{section show=$draft_list}

... etc.

Marat M.

Wednesday 20 July 2005 5:09:22 am

What I can do is to fetch the current user with this code:

{let user=fetch( 'user', 'current_user' )}
{$user.login}
{/let}

Displays login of the currently logged in user:

 marat

But how can I fetch the objects (products in my case) related to the current user ($user) then?

Tore Jørgensen

Wednesday 27 July 2005 12:35:09 am

Hi! This isn't quite an answer to your question, but might be usefull anyway...

If a user is allowed to read only some nodes within a tree, a fetch( 'content', 'tree',
hash( 'parent_node_id', $your_rootnode)
will return all the elements the user is allowed to read under $your_rootnode even if he is not allowed to read $your_rootnode.

So if using the role system is an alternative, this might be a solution.

Tore Jørgensen

Wednesday 27 July 2005 12:42:57 am

Or you can just fetch all the nodes, loop through them and only show them {if eq($user.contentobject_id, $node.data_map.<...>.your_related_object.contentobject_id)}

or something like that.

Tore Jørgensen

Wednesday 27 July 2005 2:11:47 am

It should probably be

{if eq($user.contentobject_id, $node.data_map.your_related_object.content.id)}

Use {$node.data_map|attribute("show")} to find what you need to compare.

Łukasz Serwatka

Wednesday 27 July 2005 2:25:44 am

<i>Or you can just fetch all the nodes, loop through them and only show them</i>

This will a less efficient when you have thousand of nodes. I suggest to create template operator where one of parameters will be user_id and which will return sql result array for example. All data are stored in database. Look in to documentation how to create template operator.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Nabil Alimi

Friday 29 July 2005 9:37:24 am

I have (had) somehow the same problem and I solved it by the method described by Tore Jørgensen. But just like Lukasz warned, when the number of nodes increases, speed response awfully drops.
Will the search function help in this case ?
Or what is the syntax to use if I plan to use the "attribute_filter" parameter ?

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr