i would like to automatically export all products of my webshop at the first day of the month right after 00:00.

I do know how to export them manually with the export functionality and know how to set a cron for this.

But is there to export all products with the attributes? And preferably only all products with qty 1 or more ...

I have Magento 1.8.1 CE

1 Answer 1


I figured it out myself.

By using this code. Naming this: export_mail.php


 * Import/Export Script to run Import/Export profile
 * from command line or cron. Cleans entries from dataflow_batch_(import|export) table

$mageconf = './app/etc/local.xml';  // Mage local.xml config
$mageapp  = './app/Mage.php';       // Mage app location
$logfile  = 'export_data.log';      // Import/Export log file

/* uncomment following block when moved to server - to ensure this page is
 * not accessed from anywhere else

if ($_SERVER['REMOTE_ADDR'] !== 'server ip') {
 die("You are not a cron job!");

/* System -> Import/Export -> Profiles get profile ID from
 * Magento Import/Export Profiles

$profileId = 2;

/* Post run housekeeping table bloat removal
 * imports use "dataflow_batch_import" table
 * exports use "dataflow_batch_export" table

$table = 'dataflow_batch_export';

/* Scan Magento local.xml file for connection information */

if (file_exists($mageconf)) {

$xml = simplexml_load_file($mageconf, NULL, LIBXML_NOCDATA);

$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;


else {
    Mage::log('Export script failed to open Mage local.xml', null, $logfile);
    exit('Failed to open Mage local.xml');

/* Initialize profile to be run as Magento Admin and log start of export */

require_once $mageapp;

$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
if (!$profile->getId()) {
    Mage::getSingleton('adminhtml/session')->addError('ERROR: Incorrect profile id');

Mage::log('Export ' . $profileId . ' Started.', null, $logfile);

Mage::register('current_convert_profile', $profile);
$recordCount = 0;
$batchModel = Mage::getSingleton('dataflow/batch');

Mage::log('Export '.$profileId.' Complete. BatchID: '.$batchModel->getId(), null, $logfile);

echo "Export Complete. BatchID: " . $batchModel->getId() . "\n";
/* sent file */
require_once 'app/Mage.php';
umask( 0 );
Mage :: app( "default" );
$mail = new Zend_Mail();
$mail->setFrom('[email protected]', 'Admin');
$mail->addTo('[email protected]', 'Info');
$dir = Mage::getBaseDir();
$path = $dir.DS.'var'.DS.'export'.DS.'export_product_stocks.csv';
$file = $mail->createAttachment(file_get_contents($path));
$file ->type        = 'text/csv';
$file ->disposition = Zend_Mime::DISPOSITION_INLINE;
$file ->encoding    = Zend_Mime::ENCODING_BASE64;
$file ->filename    = 'export_product_stocks.csv';
echo "E-mail sent";

/* Connect to Magento database */


mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());

/* Truncate dataflow_batch_(import|export) table for housecleaning */

$querystring = "TRUNCATE ".$db['pref'].$table;

mysql_query($querystring) or die(mysql_error());


Which is being run with a cronjob by: wget http://mywebsite.com/export_mail.php

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.