Try with below way.
Step 1 : Create block file.
<?php
namespace Namespace\Modulename\Block;
class BestSeller extends \Magento\Framework\View\Element\Template
{
protected $_collectionFactory;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory $collectionFactory,
array $data = []
) {
$this->_collectionFactory = $collectionFactory;
parent::__construct($context, $data);
}
public function getBestSellerData(){
$bestSellerProdcutCollection = $this->_collectionFactory->create()
->setModel('Magento\Catalog\Model\Product')
->setPeriod('month');
$bsProducts = $bestSellerProdcutCollection->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
->load();
return $bsProducts;
}
}
Step 2 : Create phtml file to display collection.
<?php
$bestSeller = $block->getBestSellerData(); ?>
<h1>Best Seller Collection.....</h1>
<ul>
<?php foreach ($bestSeller as $product) {
?>
<li><?php echo $product->getProductName();?>--<?php echo $product->getQtyOrdered();?></li>
<?php } ?>
</ul>
Note : Use Factory methode insted of object manager.
I hope it works!
addFilter('type_id', 'simple')
insted ofaddAttributeToFilter()