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

Import / Export can´t be automated ? 
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

Hi,
I tried magentos inetrnal import mechanism, and it works really well! But I can´t find a way to automate it. Am I blind, or there is really no way to automate import/export of products?
The only attribute I need to update is products quantity. Yes, I can write custom script, which will communicate directly with database, but it´s really uncomfort. So I hope there is some way to get automated import to work(?)

---
Sorry for my english
JD

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

Really no way to automate it? :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gruik
Member
 
Total Posts:  60
Joined:  2009-12-16
France
 

Hi,

Automate it from what kind of event?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

You can run export or import in administration by clicking on System -> Import/Export > Profiles > and selecting some of your profile. There are a few profiles by default ( for example “Import All Products") - we are using this profile (Import All Products) for importing products from CSV file hosted on another FTP server. But we have to click on the “run profile” button every time we want to run the import. This is what we want to automate - running this profile automaticaly. I spent hours with searching the web for the solution, but with no result :| Any help will be appreciated.

---
Sorry for my English

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gruik
Member
 
Total Posts:  60
Joined:  2009-12-16
France
 
jadvo - 04 February 2010 11:54 PM

This is what we want to automate - running this profile automaticaly.

And i ask : WHEN ?
Or maybe you just want a kind of shortcut?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

approximately every hour

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gruik
Member
 
Total Posts:  60
Joined:  2009-12-16
France
 

(finally xD)
So this is a cron job
http://www.magentocommerce.com/wiki/how_to/how_to_setup_a_cron_job

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

yep, this is a cron job smile thanks, I hope I can set it up..

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

I got it ! smile
This thread: http://www.magentocommerce.com/boards/viewthread/8542/ helped me very much. So if someone needs to automate export or import, go there and the second post is all you need.
Many thanks to Gruik and srinigenie smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
jadvo
Member
 
Avatar
Total Posts:  52
Joined:  2009-04-14
Melmek
 

One think: with the script from second post from http://www.magentocommerce.com/boards/viewthread/8542/ you can´t get the products to update in magento version 1.3+

the solution is to replace

Mage::app();
to
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

so the result will look like this:

<?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()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

  
$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);
 
?>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top