I get best seller product for all category using below code
public function __construct(\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory
) {
$this->_collectionFactory = $collectionFactory;
}
public function getBestSellerData()
{
$collection = $this->_collectionFactory->create()->setModel(
'Magento\Catalog\Model\Product'
);
return $collection;
}
How can i add category filter for collection. in magento 1 we can do like that
$catNum = 7; //The number of the category you want to load
$category = Mage::getModel('catalog/category')->load($catNum);
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addCategoryFilter($category);