I have an AJAX GET
call that should count all the products matching three different taxonomies.
- Product families
- Sectors of application
- Liquids suitable for the product
so in the form the user could select pumps
, agriculture
, diesel
and the controller called should count the products that matches all those criteria.
I get the solution in the templating engine:
{% set relationParams = ['and', id1, id2, id3 ] %}
{% set products = craft.entries.section('products').relatedTo(relationParams) %}
But something is not working as expected in the controller:
$prodCriteria = craft()->elements->getCriteria(ElementType::Entry)->section('products');
$prodCriteria->relatedTo = array(
'and',
'targetElement' => $catIds // Where $catIds is an array of ids
);
$products = $prodCriteria->count();
$this->returnJson( $products );
It seems like relatedTo
behave like an or
operator.
Also, is it possible to make the relatedTo behave in a more complex way, like, I want to use or
for product families and and
for other taxonomies?