I created a custom module that at regular intervals creates an XML file with selected product data. The process that generates the XML can also be run from Magento CLI via a custom command.
Although the custom command generates the feed, cron does not seem to get any products. In both cases, a helper is called that actually gets the products and writes the XML file. Here is the code that gets the products:
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
try{
$appState = $objectManager->get('MagentoFrameworkAppState');
$appState->setAreaCode(MagentoFrameworkAppArea::AREA_ADMINHTML);
} finally {
//
}
$this->collection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$this->collection->addAttributeToFilter('status', 1); //enabled
$this->collection->addAttributeToFilter('visibility', 4); //catalog, search
if( !$this->show_outofstock ) {
$this->stockFilter->addInStockFilterToCollection($this->collection);
}
$this->collection->addWebsiteFilter(1);
$this->collection->load();
$this->iterator->walk( $this->collection->getSelect(), array(array($this, 'productCallback')) );
In the cron log file I can see that the job is run (since the file is being created), but no products are in it…
Can anyone point me in the right direction with this one???