Forums / Setup & design / ezselection datatype and custom search engine

ezselection datatype and custom search engine

Author Message

laurent le cadet

Monday 18 September 2006 8:31:57 am

Hi,

I builded a class with an ezselection datatype.
This a single choice selection made of 33 possibilities.

I would like to build a custom search template based on this attribute.
This would be a select which values are dynamicaly build with a loop on the selected items of the objects.
The list of values should be "wash" from redundant item...

I could hard coded it but I want to avoid the "no match" answer.

Any hint ?

Laurent

Claudia Kosny

Tuesday 19 September 2006 10:49:19 am

Hello Laurent

I am not sure whether I understand you right so here a example setup of what I think you want to do:
You have a class with an ezselection attribute which has 33 options.
Now you might have a few objects where option1 is selected, a few where option2 is selected and none where option3 is selected. You want to display a selectbox where only those options are available that are selected in some objects, in this case the options 1 and 2 but not 3.

As far as I know the only way to achieve this is to query for each option whether there is at least one object where this is selected. As these are quite a lot of queries you should cache this block so it gets only updated if really necessary.

If you find an easier way please post it as I am currently using this approach to display product categories and I do not like it to much.

Greetings from Luxembourg

Claudia

laurent le cadet

Wednesday 20 September 2006 1:26:35 am

Hi Claudia,

That's exactly what I need.

Please, let me know how is your query for option of each objetcs.

At this time, I have no other idea.

Laurent

Claudia Kosny

Wednesday 20 September 2006 1:29:06 pm

Hello Laurent

As you selection is fortunately a single selection such a query is fairly easy. So alltogether I would create such a selectbox like this:
- Fetch the class attribute for this object attribute to get an array with the ids and the corresponding clear names of all options.
- Go through each item in this array and make a simple fetch to check whether there is at least one object where the current option is selected. Something like this:

{set $testNodesArr = fetch('content', 'tree', hash ('parent_node_id', 2,
                                                                'limit', 1,
                                                                'attribute_filter', array( array( '<your_class>/<your-selection_attribute_identifier>', '=', <id of current option>))))}

If possible, it might be a good idea to use a better parent node and use list instead of tree. Also an limitation to the class type might be good, I was just to lazy to look up the proper syntax.
If $testNodesArr exists and has at least one item, there is a object where the current option is selected so add this option to the selectbox.

As you can see this is something which should be well cached.

Greetings from Luxembourg

Claudia