1

I'm trying to make a product search engine and i need add a filter attribute option.

(i am using \Magento\Catalog\Model\Layer\Category\FilterableAttributeList)

i obtain the list of attributes

    $filterableAttributeList = $this->_filterableAttributeList->getList();

After i obtain the values for each attribute

foreach ($filterableAttributeList as $filter) {

        $code = $filter->getAttributeCode();
        $name = $filter->getFrontendLabel();

        $entities = $this->_eavConfig
                            ->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $code)
                            ->getSource()->getAllOptions();

}

and finally for each option i want to count the number of products that match with that option but always return 0.

        foreach ($entities as $entity){

            $label = $entity["label"];
            $value = $entity["value"];

            if($label == " ") continue;


            $queryValue = [];
            $queryValue[$code][] = $value;

                $products = $this->_catalogSearchAdvanced
                    ->addFilters($queryValue)
                    ->getProductCollection()
                    ->addStoreFilter($storeId);

                $total = $products->count();

    }

any idea?

  • may be the problem is your array $queryValue[$code][] = $value; try instead $queryValue[$code] = $value; – Piyush Jun 22 '17 at 13:21
  • no, isnt it. but thanks! – Miguel Jun 22 '17 at 13:42
  • Did you got the solution ? – GNANA May 25 '18 at 17:54

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.