In this post I am going to explain how to get product collection by category in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_categoryFactory; protected $_productCollectionFactory; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, array $data = [] ) { $this->_categoryFactory = $categoryFactory; $this->_productCollectionFactory = $productCollectionFactory; parent::__construct($context,…


Recent Comments