Is there anyway to display best seller products by date range? For example recent last 7 days or recent 30 days or recent 60 days, etc. I have got a help that thing. But it is in Magento 1.9, not 2.x from here https://stackoverflow.com/questions/48299911/get-last-7-days-best-selling-items-magento-1-9 and I've tried a lot in Magento 2.3, but shows a blank page that's main code are given below:

    $bestSellers = $this->_bestSellersCollectionFactory->create();

    $bestSellers->addAttributeToSelect('*')->addFieldToFilter('created_at', array(
                'from'=> date('Y-m-d H:i:s', strtotime('-7 days')),
                'to' => date('Y-m-d H:i:s')

   foreach ($bestSellers as $product) {
            $productIds[] = $product->getProductId();

   $collection = $this->productCollectionFactory->create()->addIdFilter($productIds);

    return $collection;

I cann't understand where I'm wrong and how to implement this thing. If any one knows, please help me. Thank You.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.