Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

“product import/export” “order import/export” Cron with my erp
 
jack001
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2007-11-29
France
 

Hello,

I know how to import/export products, orders manually. But is it possible to set up a CRON on my server to do it.
My ERP can export or import files on my server (every hours, or x time a day...) but i want Magento to import the csv file automiticaly.
Is it possible?
regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

If the cron can run PHP code which (or .php file) which it can just knowing how the newsletters work then there is no reason it can’t do that if given the file it needs to run.  Just make a PHP with the necessary code in there for exporting the csv or importing and run that cron script.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
jack001
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2007-11-29
France
 

thank you
i’ll try it

 
Magento Community Magento Community
Magento Community
Magento Community
 
jack001
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2007-11-29
France
 

i found this topic:

http://www.magentocommerce.com/boards/viewthread/8542/

thanks to “srinigenie"… i will test

“Pasting the code that helped me to import products using a cron-

STEP 1: Save the below file as Cron_Import.php on the Magento base folder.

<?php
//uncomment when moved to server - to ensure this page is not accessed from anywhere else
//if ($_SERVER['REMOTE_ADDR'] !== '<your server ip address') {
//  die("You are not a cron job!");
//}

require_once 'app/Mage.php';
// wget -O - http://<www.example.com>/Cron_Import.php/?files=3XSEEEE.csv
  
umask(0);

  
//$_SERVER['SERVER_PORT']='443';
  
Mage::app();

  
$profileId 3//put your profile id here
  
$filename Mage::app()->getRequest()->getParam('files'); // set the filename that is to be imported - file needs to be present in var/import directory  
  
if (!isset($filename))  {
 
die("No file has been set!");
  
}
  $logFileName
$filename.'.log';  
  
$recordCount 0;

  
Mage::log("Import Started",null,$logFileName);  
 
  
$profile Mage::getModel('dataflow/profile');
  
  
$userModel Mage::getModel('admin/user');
  
$userModel->setUserId(0);
  
Mage::getSingleton('admin/session')->setUser($userModel);
  
  if (
$profileId{
    $profile
->load($profileId);
    if (!
$profile->getId()) {
      Mage
::getSingleton('adminhtml/session')->addError('The profile you are trying to save no longer exists');
    
}
  }

  Mage
::register('current_convert_profile'$profile);

  
$profile->run();
  
  
$batchModel Mage::getSingleton('dataflow/batch');
  if (
$batchModel->getId()) {
    
if ($batchModel->getAdapter()) {
      $batchId 
$batchModel->getId(); 
      
$batchImportModel $batchModel->getBatchImportModel();
      
$importIds $batchImportModel->getIdCollection();  

      
$batchModel Mage::getModel('dataflow/batch')->load($batchId);      
      
$adapter Mage::getModel($batchModel->getAdapter());
      foreach (
$importIds as $importId{
        $recordCount
++;
        
try{
          $batchImportModel
->load($importId);
          if (!
$batchImportModel->getId()) {
             $errors[] 
Mage::helper('dataflow')->__('Skip undefined row');
             continue;
          
}

          $importData 
$batchImportModel->getBatchData();
          try 
{
            $adapter
->saveRow($importData);
          
catch (Exception $e{
            Mage
::log($e->getMessage(),null,$logFileName);          
            continue;
          
}
        
          
if ($recordCount%20 == 0{
            Mage
::log($recordCount ' - Completed!!',null,$logFileName);
          
}
        } 
catch(Exception $ex{
          Mage
::log('Record# ' $recordCount ' - SKU = ' $importData['sku']' - Error - ' $ex->getMessage(),null,$logFileName);        
        
}
      }
      
foreach ($profile->getExceptions() as $e{
        Mage
::log($e->getMessage(),null,$logFileName);          
      
}
      
    }
  }
  
echo 'Import Completed';
  
Mage::log("Import Completed",null,$logFileName);
 
?>

STEP 2: Next step would be to turn on the logging in Admin so that the log file is created.  (Navigation: System->Configuration->Developer->Log Settings)

STEP 3: Test this on your SSH login to check if this works on command line. Use the below command
wget -T0 -t1 -O - http://<www.example.com>/Cron_Import.php/?files=3XSEEEE.csv
Note here that the file to be imported is passed as parameter in the URL. Susbtitute ‘3XSEEEE.csv’ with your CSV name.

The completion of the above command should create a log file with name <your CSV file name>.log in the var/log directory. Open this file to see the log messages.

STEP 4: Now setup your Cron with the command mentioned in STEP 4. See if the log file gets created once the cron is activated and runs to completion.

Note: You can make it better by ensuring MAIL TO attribute is set for the Cron so that a mail is sent to inform the completion of the cron.”

 
Magento Community Magento Community
Magento Community
Magento Community
 
vengiss
Jr. Member
 
Total Posts:  13
Joined:  2009-03-25
 

Thanks for the script, works with 1.3 as well

 
Magento Community Magento Community
Magento Community
Magento Community
 
aiva
Jr. Member
 
Total Posts:  17
Joined:  2009-02-04
 

No it does not work fully with 1.3 - it works for importing new products but not updating them. It worked for versions prior to 1.3.0

Original thread and possilbe solution -> http://www.magentocommerce.com/boards/viewthread/8542

 
Magento Community Magento Community
Magento Community
Magento Community
 
bolasevich
Sr. Member
 
Avatar
Total Posts:  235
Joined:  2008-03-04
Newington, CT USA
 

i created a true dataflow export orders to csv module. http://www.magentocommerce.com/extension/2063

this will do the export part no problem

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top