I am having problem with collection filter

I am using event catalog_product_collection_apply_limitations_after to add collection limitations

In the observer i am using below code to apply filter.

public function execute(\Magento\Framework\Event\Observer $observer)
    $collection = $observer->getEvent()->getCollection();
    return $this;

It is throwing Exception #0 (RuntimeException): Illegal state


Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection::addFieldToFilter($field, $condition = null)

there is code that check $this->searchResult

 if ($this->searchResult !== null) {
        throw new \RuntimeException('Illegal state');

check exception trace here


How to fix this if i remove throw new \RuntimeException('Illegal state'); then it is working but it's not a good idea right ?

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.