I am trying to get product list from specific category id. i am using magento 2.2.1 version.
below are my code of Block File : view.php i want to override this file from vender.
Here is my custom module :
app\code\Narola\Magentocatalog\Block\Category\View.php
namespace Narola\Magentocatalog\Block\Category;
class View extends \Magento\Catalog\Block\Category\View
{
protected $_productCollectionFactory;
protected $_categoryFactory;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
array $data = []
) {
$this->_categoryFactory = $categoryFactory;
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}
public function getSubcategory($catId)
{
$objectManagerr = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManagerr->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$collection = $categoryFactory->create()
->addFieldToFilter('parent_id', $catId)
->addAttributeToSelect('*');
return $collection;
}
public function getSubcategory_product($sub_catid){
$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;
}
}
==============================
Here when i add constructor i am getting below error.
Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Catalog\Block\Category\View::__construct() must be an instance of Magento\Catalog\Model\Layer\Resolver, array given, called in C:\wamp64\www\magento_221\app\code\Narola\Magentocatalog\Block\Category\View.php on line 18 and defined in C:\wamp64\www\magento_221\vendor\magento\module-catalog\Block\Category\View.php on line 45
If any one has solution regarding this then please provide me.