Skip to main content
added 557 characters in body
Source Link
harri
  • 5.5k
  • 6
  • 46
  • 103

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

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show.  This filter 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 fine this may be due to a bug in 2.1.x see here: https://github.com/magento/magento2/issues/9195 Ok so after looking again today i'm not sure this is the best method of achieving a filter as a lot of posts on here with issues however 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

I tested this and the 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; } } There are a few issues however for me i noticed that the layered navigation counts were not updated correctly which is what `getSize()` should sort out.  This filter also didn't work as expected for me 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** Not sure if this is the same bug but has been mentioned and apparently fixed but i couldn't find a workaround: https://github.com/magento/magento2/issues/9195 After looking again today i'm not sure this is the best approach for achieving an additional filter as there are lot of posts on here with issues with 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
added 557 characters in body
Source Link
harri
  • 5.5k
  • 6
  • 46
  • 103

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show. This filter 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 from working properly andfor some filters seem to be off although toolbar seems fine this may be due to a bug in 2.1.x see here: https://github.com/magento/magento2/issues/9195 Will look for a workaround for you and check ifOk so after looking again today i'm not sure this is fixed inthe best method of achieving a filter as a lot of posts on here with issues however the 2 cases with a solution show a slightly more long winded approach of achieving this however works.2 See below answers that may help you further to get this working correctly: https://magento.xstackexchange.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

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show. This filter 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 from working properly and may be due to a bug in 2.1.x see here: https://github.com/magento/magento2/issues/9195 Will look for a workaround for you and check if this is fixed in 2.2.x.

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show. This filter 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 fine this may be due to a bug in 2.1.x see here: https://github.com/magento/magento2/issues/9195 Ok so after looking again today i'm not sure this is the best method of achieving a filter as a lot of posts on here with issues however 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
added 87 characters in body
Source Link
harri
  • 5.5k
  • 6
  • 46
  • 103

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show. This filter 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 from working properly but not sure why this is failing I will haveand may be due to a little playbug in 2.1.x see here: https://github.com/magento/magento2/issues/9195 Will look for a workaround for you and update furthercheck if this is fixed in 2.2.x.

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show. This filter 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 from working properly but not sure why this is failing I will have a little play and update further.

I tested this and that error doesn't seem to be coming from the addAttributeToFilter but seems to start when $collection->getSize(); is used.

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 goes for me when not added and filters show. This filter 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 from working properly and may be due to a bug in 2.1.x see here: https://github.com/magento/magento2/issues/9195 Will look for a workaround for you and check if this is fixed in 2.2.x.
added 142 characters in body
Source Link
harri
  • 5.5k
  • 6
  • 46
  • 103
Loading
added 357 characters in body
Source Link
harri
  • 5.5k
  • 6
  • 46
  • 103
Loading
Source Link
harri
  • 5.5k
  • 6
  • 46
  • 103
Loading