This is my block
<?php
namespace Xlabs\Ajaxscroll\Block\Product;
class Ajaxscroll extends \Magento\CatalogWidget\Block\Product\ProductsList
{
protected $productCollectionFactory;
protected $_categoryFactory;
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
array $data = []
){
$this->productCollectionFactory = $productCollectionFactory;
$this->_categoryFactory = $categoryFactory;
}
public function getProductList(){
$categoryId = 12;
$category = $this->_categoryFactory->create()->load($categoryId);
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addCategoryFilter($category);
$collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
$collection->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
return $collection;
}
}
Blockquote
and i am getting the error
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/sample221/vendor/magento/framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/sample221/generated/code/Techievolve/Ajaxscroll/Block/Product/Ajaxscroll/Interceptor.php(830): Magento\Framework\View\Element\AbstractBlock->toHtml() #1 /var/www/html/sample221/vendor/magento/framework/View/Layout.php(558): Techievolve\Ajaxscroll\Block\Product\Ajaxscroll\Interceptor->toHtml() #2 /var/www/html/sample221/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('Ajaxscroll_bloc...') #3 /var/www/html/sample221/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('Ajaxscroll_bloc...') #4 /var/www/html/sample221/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('Ajaxscroll_bloc...') #5 /var/www/html/sample221/generated/code/Magento/Framework/View/Layout/Intercep in /var/www/html/sample221/vendor/magento/framework/View/Element/AbstractBlock.php on line 652