Is it possible to refresh report statistics via cron job. Does Magento2 support refresh via cron feature out of the box?

2 Answers 2


Yes, it is possible.

First, pass "reportTypes" argument to your cron class by using di.xml like below

<type name="Vendor\Module\Cron\CronFile">
            <argument name="reportTypes" xsi:type="array">
                <item name="sales" xsi:type="string">Magento\Sales\Model\ResourceModel\Report\Order</item>
                <item name="tax" xsi:type="string">Magento\Tax\Model\ResourceModel\Report\Tax</item>
                <item name="shipping" xsi:type="string">Magento\Sales\Model\ResourceModel\Report\Shipping</item>
                <item name="invoiced" xsi:type="string">Magento\Sales\Model\ResourceModel\Report\Invoiced</item>
                <item name="refunded" xsi:type="string">Magento\Sales\Model\ResourceModel\Report\Refunded</item>
                <item name="coupons" xsi:type="string">Magento\SalesRule\Model\ResourceModel\Report\Rule</item>
                <item name="bestsellers" xsi:type="string">Magento\Sales\Model\ResourceModel\Report\Bestsellers</item>
                <item name="viewed" xsi:type="string">Magento\Reports\Model\ResourceModel\Report\Product\Viewed</item>

Then, in your cron file,

namespace Vendor\Module\Cron;
use Magento\Reports\Model\ResourceModel\Refresh\Collection;

class CronFile extends Collection
    protected $logger;
    protected $reportTypes;

    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
        \Magento\Reports\Model\FlagFactory $reportsFlagFactory,
        \Psr\Log\LoggerInterface $logger,
        array $reportTypes
    ) {
        $this->logger = $logger;
        $this->reportTypes = $reportTypes;
     * @return $this
    public function execute()
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

        try {
            $codes = $this->loadData();

            foreach ($codes->_items as $codek=>$codev) {
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
        } catch (\Exception $e) {
        return $this;
  • Did it work for you ? Commented Sep 26, 2018 at 19:18
  • Yes, it works perfectly for me.
    – Pribhav
    Commented Sep 27, 2018 at 5:08
  • @Sarasranglt, Doesn't it work for you?
    – Pribhav
    Commented Sep 27, 2018 at 5:39
  • worked fine (+1) Commented Oct 7, 2019 at 8:51

where exactly do I put these 2 files. I use the luma theme directly in /[webroot]/vendor/magento/theme-frontend-luma/

Thanx. Thomas.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.