My dear collection,
The way you are linking the tags is not feasible, do.
Think that bringing products with mandatory A, B and C tags, would have to have subquerys:
<?php
$criterios = array(
'Produto.publicado'=>1,
'Produto.titulo LIKE'=>"%$kw%",
'AND' => array(),
);
foreach ($tags as $tag){
$criterios['AND'][] = array('TagsProduto.tag_id'=>$tag);
}
?>
See above a way to do what you want, but it makes no sense, because Tagsproduto.id has only 1 value on the line, or 1 ID of Tagsproduto per line.
To bring products with A, B and C tags, you have to do something like:
<?php
$prodTag = array();
foreach ($tags as $tag){
$prodTag[] = "Produto.id = (SELECT produto_id FROM tags_produto WHERE id={$tag} AND produto_id=Produto.id)";
}
$tags = implode(' AND ', $prodTags);
$this->Produto->find('all', array('conditions'=>array(
$tags,
)));
?>
could you post an example of the $tags array? It’s easier to understand.
– Marcelo Aymone