3

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?

2
  • Any update on this issue? I am having the same problem
    – Sarvagya
    May 17 '18 at 8:54
  • we implemented a work-around - see posted answer. May 18 '18 at 18:44
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');
        $this->_entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
        if(!empty($curPage) && !empty($pageSize)) {
            $this->_entityCollection->setPage($curPage, $pageSize);
        }
        $this->_prepareEntityCollection($this->_entityCollection);
    }
    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, privacy policy and cookie policy

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