-
☆ A M B ☆
- 279 Posts
Hi All,
I can understand this topic title is a little confusing; I hope I could explain it here a little more.
I have an product overview, build with getResources. For every product I have made a TV named ’productBrand’. Where the value of this TV always is a resource id. (every brand is a resource). Now I want to filter the results on this brand. So I parse a multiple select value (eq. array) in the URL like:
...?brand[]=204&brand[]=312
A simple snippet of my own builds a string like:
productBrand==204||productBrand==312
This one is parsed into the getResources ’tvFilters’ option. So far, so good.
When I had one brand selected, so one brand to filter, the result is as expected. Only products with that brand are shown. But when I had multiple brands selected, as above, the result shows me every product, also products with a different brand.
Could anyone help me out? Thanks in advance
Regards, Bert
-
☆ A M B ☆
- 279 Posts
No I don’t; because the ID’s could be 1 or 100 or 10.. I don’t know, so a wildcard isn’t an option.
I read that topic and there was suggest to use the alias (a name) instead of ids, but with a little 600/700 products it isn’t easy to change this :-( no other options for me?
you can try this (not tested, maybe buggy):
<?php
//[[!getRequested? ¶m=`brand` &tvname=`productBrand` ]]
//[[+requestedIds]]
$tvname = $modx->getOption('tvname',$scriptProperties,'');
$toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,1);
if (! empty($tvname))
{
$tvObject = $modx->getObject('modTemplateVar', array ('name'=>$tvname));
$tmplvarid = $tvObject->get('id');
$values = $_GET[$param];
$c = $modx->newQuery('modTemplateVarResource');
$c->where( array ('tmplvarid'=>$tmplvarid, 'value:IN'=>$values));
//$c->prepare();echo $c->toSql();
if ($resources = $modx->getCollection('modTemplateVarResource', $c))
{
foreach ($resources as $resource)
{
$ids[] = $resource->get('contentid');
}
$ids=implode(',', $ids);
if (!empty($toPlaceholder)){
$modx->setPlaceholder('requestedIds',$ids);
return '';
}
return $ids;
}
}
$ids = '0';
if (! empty($toPlaceholder))
{
$modx->setPlaceholder('requestedIds', $ids);
return '';
}
return $ids;
call ist like this:
[[!getRequested? ¶m=`brand` &tvname=`productBrand` ]]
[[+requestedIds]]
if it works you can use getResources with
&resources=`[[+requestedIds]]`
did you try it with getResources alone?
Hello,
I am working on the same kind of filtering and I have noticed that the "resources" parameter of getResources is adding products to a current list.
I dont want the "resources" parameter to add things to a list of products.
Is that possible that the "ressources" parameter only shows the products that are defined in ?
For example, I have a folder "products (id = 5)" in which I have 10 products and only want to display products with id 8 and 9 of that folder.
So the call will be :
[[!getResources? &parents=`5` &tpl=`product` &processTVs=`1` &resources=`8,9` &includeTVs=`1` &tvPrefix=``]]
But it’s not only showing the products 8 and 9.
Any solution ?
Thanks
Sam
-
☆ A M B ☆
- 279 Posts
For as far I know, the parents parameter doesnt need to be given then. Only ’resources’ is required then.. correct me if I’m wrong
-
MODX Staff
- 10,725 Posts
Try setting the &parents property to -1 — otherwise, it will assume the current Resource as the parent and include it’s children in addition to the specific Resources you include via the &resources property.