1

I'm using multiple layered navigation filter (https://github.com/SlavaYurthev/MultipleLayeredNavigation-M2) is allows to select multiple categories at once. But categories filter is not working, I want to filter by subcategories. In Model\Layer\Filter\Category there is

$collection->addCategoriesFilter2(['in' => $values]);

but this code doesn’t add condition to sql where. I think problem is that this function is already used to add parent category filter. So calling this function twice do nothing and ignores. When I created duplicate of this function with new table alias (cat2) it is working:

public function addCategoriesFilter2(array $categoriesFilter)
{
    foreach ($categoriesFilter as $conditionType => $values) {
        $categorySelect = $this->getConnection()->select()->from(
            ['cat2' => $this->getTable('catalog_category_product')],
            'cat2.product_id'
        )->where($this->getConnection()->prepareSqlCondition('cat2.category_id', ['in' => $values]));
        $selectCondition = [
            $this->mapConditionType($conditionType) => $categorySelect
        ];
        $this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
    }
    return $this;
}

Am I right, this is the problem?

My second question is Preprocessor class is this module (Plugin\Model\Adapter\Mysql\Filter). What is it used for? I see it adds some conditions to categories and price filter. Why it adds only for this fields and e.g. not for attributes fields? With this code commented it like it is also working.

Thx for any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.