We have a custom CRON command defined in the etc/di.xml file but we noticed that when it runs it fires frontend events. The job runs data export. We see that if we use the admin UI to run a standard Magento export, the scope is in the admin and no frontend events fire, but when we run our export job via CRON, frontend events fire. This causes problems as the product collection has extra filters added that we don't want.

Anyone know how to set the CRON command to only run as admin scope?

  • Any update on this issue? I am having the same problem
    – Sarvagya
    May 17, 2018 at 8:54
  • we implemented a work-around - see posted answer. May 18, 2018 at 18:44

1 Answer 1


We resolved this by implementing a work-around by "resetting" the collection each call to collectRawData. To do this we overwrite the Magento\CatalogImportExport\Model\Export\Product model and update a couple methods:

protected function collectRawData() {
    $collection = $this->_getEntityCollection(true); // pass true to 'reset' collection. this will clear filters.

protected function _getEntityCollection($resetCollection = false) {
    if($resetCollection && $this->_entityCollection) {
        // be sure to save the page info form the current collection. by 
        // default magento will page at 5000 records.
        $curPage = $this->_entityCollection->getCurPage();
        $pageSize = $this->_entityCollection->getPageSize();
    if ($resetCollection || empty($this->_entityCollection)) {
        $this->_entityCollection = $this->_entityCollectionFactory->create();
        $this->_entityCollection->setOrder('has_options', 'asc');
        if(!empty($curPage) && !empty($pageSize)) {
            $this->_entityCollection->setPage($curPage, $pageSize);
    return $this->_entityCollection;

... not certain if there are any side-effects but this seemed to resolve the issue since resetting the collection removes filters.

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.