Get objects witn setCodition and AddCondition


#1

Hello.

Could someone help me to get result from these condition. The field Categories in Object Relation type.
First I try to get product with category param and than check products with subcategory. I see that setCondition works fine, I’ve got the products, but AddcontionParam doesn’t return any result.

   $list = new Product\Listing();
        $category = ShopCategory::getIdFromKey($params['category']);
        $list->setCondition("categories like '%,".$category->getId().",%'");
        $children_category_array = array();
        foreach ($category->getChildren() as $children) {
              $list->addConditionParam("categories like '%,?,%'", [$children->getId()], "OR");
        }

    }
    $list->load();

#2

I tried a lot of variants and I don’t know why, but only this code is working.

$test_array = array(3, 4, 5);
foreach ($test_array as $val) {
$category_array[] = “’%,$val,%’”;
}

    $list = new \Pimcore\Model\DataObject\Product\Listing();
    $list->addConditionParam('category like ' . implode(" OR category like ", $category_array));

    $objects = $list->load();
    $this->view->entries = $objects;