I tested this and thatthe Illegal State
error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize();
is used (alteast in my case). This is on 2.1.8 installation but maybe try commenting that to see if your filters then show:
addAttributeToSelect('bgs_stock_status');
$collection->addAttributeToFilter(
[
['attribute' => 'bgs_stock_status', 'is' => new \Zend_Db_Expr('null')],
['attribute' => 'bgs_stock_status', 'lt' => 3],
]);
//$collection->getSize();
return $collection;
}
}
Try commenting this line as error goesThere are a few issues however for me
wheni noticed that the layered navigation counts were not
added and filters showupdated correctly which is what `getSize()` should sort out.
This filter
also didn't work as expected for me
tho as null products were not showing so I did this however seems to be working fine for you thought i would mention anyway:
$collection->addAttributeToFilter('bgs_stock_status',
array('or'=> array(
0 => array('lt' => '3'),
1 => array('is' => new \Zend_Db_Expr('null')))
), 'left');
**Update**
Ok so that stops the counts for some filters seem to be off although toolbar seems fineNot sure if this
may be due to ais the same bug
in 2.1.x see herebut has been mentioned and apparently fixed but i couldn't find a workaround:
https
https://github.com/magento/magento2/issues/9195
Ok so afterAfter looking again today i'm not sure this is the best
method ofapproach for achieving
aan additional filter as
athere are lot of posts on here with issues
however thewith this method.
The 2 cases with a solution show a slightly more long winded approach of achieving this however works. See below answers that may help you further to get this working correctly:
https://magento.stackexchange.com/questions/142562/how-to-update-category-page-with-custom-filters-and-also-layered-navigation-ma/146736
https://magento.stackexchange.com/questions/172690/magento-2-1-6-product-grid-page-count-and-record-count-issue-when-programmatical