0
$_productCollection = $block->getLoadedProductCollection();
$_productCollection->clear()
        ->addAttributeToFilter('author', array('eq' => 'Author-1'))
        ->load();
$this->setCollection($_productCollection);

1 Answer 1

0

I would suggest taking a different approach to leverage native Magento functionality with custom filterable attributes.

After double-checking the attribute settings are compatible, for example that the author attribute's setting is configured to enable it as a filterable attribute, then change the way that you are handling the product listing so that native Magento functionality will handle proper product collection filtering when filtered by author. If you are attempting to filter per a specific author, you can do rewrites, or create custom pages that pre-apply the filter by simple url parameters.

Review attribute creation and usage:

http://docs.magento.com/m2/ee/user_guide/stores/attribute-product-create.html


Side note: You are obtaining a loaded product collection from a block, then setting it within $this. I'm certain that there are different code approaches that must be taken before and after the collection has been loaded. I am unsure if a loaded collection can simply be cleared, then work properly with addAttributeToFilter(...) method. I would think that even if it does work, you would still want to $block->setLoadedProductCollection($_productCollection);, instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.