1

I've created an attribute for my categories (it's displayed on back-office and I can save values).

In sur php file Result.php for the research process, I want to add this attribute as a filter.

how to I do that ? In _getProductCollection I've added this line :

    $this->productCollection = $this->getListBlock()->getLoadedProductCollection();
    $this->productCollection->getSelect()->join(array('cats' => 'catalog_category_product'), 'cats.product_id = e.entity_id');
    $this->productCollection->getSelect()->group("cats.attribute");

But it shows non filtered result

Any thoughts ?

  • If I remember correctly the catalog_category_product table is just a pivot table containing the ID of the product and category and position. If you want to add a group of your category attribute it will be a bit more complex if you're doing it like this because categories are EAV entities so you'll have to join a few tables to get your value. I don't fully grasp why you're grouping products by a category attribute. Should the attribute be on the product instead, or the grouping done on a collection of categories? – rain2o Apr 4 at 14:30
  • Please see my other "old" post. magento.stackexchange.com/questions/266723/… – Morgan Tartreau Apr 4 at 14:37
  • Maybe try using addCategoryIds on the collection first and then see if you can do a join. Part of the challenge here is the fact that products can belong to multiple categories so that could cause a complication in the joining and grouping. – rain2o Apr 4 at 15:03
  • Already tried, but not a success – Morgan Tartreau Apr 4 at 15:06
  • What file should I override to do that ? – Morgan Tartreau Apr 4 at 16:04

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.