Forums / General / attribute_filter on fetch content list?

attribute_filter on fetch content list?

Author Message

herve croce

Thursday 24 July 2008 7:38:49 am

I don't understand why this is not working.
I have add a attribute to the Product class :
Support [Sélection]
Nom:Support
Identifiant:support
Drapeaux:Est requis
Recherche autorisée
Ne collecte pas d'informations
La traduction est activée
Type:Choix unique
Options:
DVD-Rom
OnLine

I create 3 products with "DVD-Rom" and one with "OnLine"
I call the http get parameters with

$view_parameters.support

My

$view_parameters.support

is ok
My

$node.node_id

is ok
I fetch like it's said on documentation :
My products are on multiple folders it's why the depth 2,

{def $child=
fetch('content', 'list', 
	hash( 'parent_node_id', $node.node_id, 
		 'depth', '2',
		 'class_filter_type',  'include', 
		 'class_filter_array', array('product'),
		 'attribute_filter', array(
						array( 'product/support', '=', $view_parameters.support)
						)
		)
	)
}

It give me no result.
If I suppress

'attribute_filter', array(array( 'product/support', '=', $view_parameters.support))

It give me all products.
I tried with : 'attribute_filter', array(array( 'product/support', 'like', $view_parameters.support))
but no way...
Is there someone have an idea to have only product with choosen support with the 'attribute_filter'?
I'm on EZ 3.9.4
Thank's a lot.

Ivo Lukac

Thursday 24 July 2008 8:49:31 am

You are using 'list' function insteda of 'tree'

Try this:

{def $child=fetch('content', 'tree', 
        hash( 'parent_node_id', $node.node_id, 
                 'depth', '2',
                 'class_filter_type', 'include', 
                 'class_filter_array', array('product'),
                 'attribute_filter', array(
                                                array( 'product/support', '=', $view_parameters.support)
                                                )
                )
        )
} 

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

herve croce

Friday 25 July 2008 1:57:45 am

Thanks for trying,
but it give me the same result... nothing.
And if I suppress

'attribute_filter', array(array( 'product/support', '=', $view_parameters.profil))

It give me all products like with 'list'

I mix the examples from http://ez.no/doc/ez_publish/technical_manual/3_9/reference/modules/content/fetch_functions/list
Example 10

{fetch( 'content', 'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( 'or',
                                        array( 152, '=', 'abc' ),
                                        array( 153, '=', '42' ) ) ) )}

This example demonstrates how to do attribute filtering. Only nodes that have attributes number 152 and 153 set to "abc" and 42 respectively will be included in the result.
Example 11

{fetch( 'content',
        'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( array( 'article/title',
                                        'like',
                                        '*story*' ) ) ) )}

This example demonstrates how to do attribute filtering. Instead of specifying the ID number of the attribute (as in the previous example), the identifier of the class and the attribute is used. Only article nodes that contain the text "story" in their title attribute will be included in the result.

Thank's for someone who have a answer to this.

Ivo Lukac

Friday 25 July 2008 2:37:13 am

What value does your $view_parameters.support have?

AFAIK for selection filtering you must use selection id.

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

herve croce

Friday 25 July 2008 7:24:38 am

It give me the result of the choosen 'product/support/options'.
Options:
DVD-Rom
OnLine
I tried with

{def $child=fetch('content', 'list', 
        hash( 'parent_node_id', $node.node_id, 
                 'depth', '2',
                 'class_filter_type', 'include', 
                 'class_filter_array', array('product'),
                 'attribute_filter', array(
                                                array( '209', '=', $view_parameters.support)
                                                )
                )
        )
}

the option_id=209
no result either...
Thanks for time you give on this.

Ivo Lukac

Friday 25 July 2008 9:18:48 am

You can't use selection text for attribute filtering.
Every selection item has text and id.

If you use {attribute_view_gui attribute=$node.data_map.your_selection} you will get selection text, if you use {$node.data_map.your_selection.content} you will get selection id.

Use selection id for filtering

NOTE: if the selection attribute is multiple you can't filter with standard attribute_filter, you must make custom extended_attribute_filter

Hope this is more clear :)

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

herve croce

Monday 28 July 2008 7:25:17 am

Thank's a lot!!
It's clear now.

code who generate GET parameters
i replace

$options.name

by

$options.id
  {def $tab_options=$class_product.data_map.support.content.options}
    {foreach $tab_options as $options}
      {if eq($module_result.view_parameters.support, $options.id)}
      <b>{$options.name}</b>
      {else}
        {if $module_result.view_parameters.language}
        <a href={concat( $Menu_produits[0].path[2].path_identification_string ,"/(support)/",
                     $options.id, "/(language)/",
                     $module_result.view_parameters.language
                     )|ezurl}>{$options.name}</a>
        {else}
        <a href={concat( $Menu_produits[0].path[2].path_identification_string ,"/(support)/",
                     $options.id
                     )|ezurl}>{$options.name}</a>
      	{/if}
      {/if}
    {delimiter}
    <br/>
    {/delimiter}
  {/foreach}

And now

{def $child=fetch('content', 'list', 
        hash( 'parent_node_id', $node.node_id, 
                 'depth', '2',
                 'class_filter_type', 'include', 
                 'class_filter_array', array('product'),
                 'attribute_filter', array(
                                                array( 'product/support', '=', $view_parameters.support)
                                                )
                )
        )
}

work's. :o)

Ivo Lukac

Monday 28 July 2008 8:29:12 am

Superb :)

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

eZ debug

Timing: Jan 18 2025 22:13:58
Script start
Timing: Jan 18 2025 22:13:58
Module start 'content'
Timing: Jan 18 2025 22:13:58
Module end 'content'
Timing: Jan 18 2025 22:13:58
Script end

Main resources:

Total runtime0.0178 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 587.7266180.8359
Module start 'content' 0.00570.0050 768.5625105.9766
Module end 'content' 0.01060.0071 874.539182.7031
Script end 0.0177  957.2422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002212.1347120.0002
Check MTime0.00105.6784120.0001
Mysql Total
Database connection0.00073.705410.0007
Mysqli_queries0.002413.512940.0006
Looping result0.00000.084220.0000
Template Total0.006837.910.0068
Template load0.00084.530110.0008
Template processing0.005933.292310.0059
Override
Cache load0.00063.229510.0006
General
dbfile0.002312.7282100.0002
String conversion0.00000.021430.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs