Automatic import using Magento cron job
2012-12-26 18:53
225 查看
Importing a large quantity of products via the shell.
When the importer loads (when the user has pressed run)it parses thecomplete source file (csv, xml) and places it in atemporary database table (dataflow_batch_import).From that table it creates a list of all the rows that need to beimported and it sends that list to the browser.The browser creates a Javascript Ajax request back to magento forevery batch (the number you configured during import).When Magento receives that request, magento starts, imports thebatch, sends the results back to the page and closes.When the page receives the results back, it prints them, and startsover with step three.http://www.h-o.nl/blog/automatic-import-with-magento-using-ssh-no-browser-needed/mag_login.php:<?php$root='/PATH/TO/YOUR/MAGENTOINSTALLATION/';$username='USERNAME';$password='PASSWORD';//gettingMagentorequire_once$root.'app/Mage.php';ob_implicit_flush();Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);//startingthe importMage::getSingleton("admin/session",array("name"=>"adminhtml"));$session=Mage::getSingleton("admin/session");try{$session->login($username,$password);}catch(Exception$e){echo'Message:'.$e->getMessage();}if(!$session->isLoggedIn()){Mage::log(convert(memory_get_usage())." - "."Could not log in with '$username'",null,$logFileName);exit;}$sessionId=$session->getEncryptedSessionId();$formKey=Mage::getSingleton('core/session')->getFormKey();echojson_encode(array('sessionId'=>$sessionId,'formKey'=>$formKey));Copy the above code to your local Magento installation, put them ina secure folder, that isn't accesible by a browser and login to theshell. Fill in the correct information into the files. After thatis done, start up your shell, browse to the folder.Run the filewith:php -f mag_import.php 7In the line above, 7 should be replaced by your own profile Id,which can be found the first column of the profiles.Making the Magento product import fully automatic.
If we got the above working, we need to get the working fullyautomatic. We want to import our products and do a complete reindexof magento every night. First we create a file that can be executedby the shell that imports the products and reindexesit. Call itsomething like import.sh (sh from shell):echomag_import.php 7php /PATH/TO/YOUR/MAGENTOINSTALLATION/shell/mag_product_import.php7echoindexer.php reindexallphp /PATH/TO/YOUR/MAGENTOINSTALLATION/shell/indexer.phpreindexallTry and run the file with the following:bash /PATH/TO/YOUR/MAGENTOINSTALLATION/shell/shell_dayly.shIf that all works properly, we can setup our cronjob to do itautomatically every night. Enter the following into you shell:crontab -eIf you already have setup your Magento cron, you should seesomething like:*/5 * * * * php -f /PATH/TO/YOUR/MAGENTOINSTALLATION/cron.phpNow, if something happens to our import, somethings goes wrong,etc, we wan't to get notified. Add the following line at the top ofthe crontab file.MAILTO=info@youremail.comBelow the Magento line we add our import cron:0 0 * * * bash/PATH/TO/YOUR/MAGENTOINSTALLATION/shell/import.shNow save the crontab (depends on the editor how) and your allset.Note: if you want to see error regarding the import, lines thatcould not be processed open/PATH/TO/YOUR/MAGENTOINSTALLATION/var/log/import.log or browse tothe file in the shell and type:tail -f import.log相关文章推荐
- Magento计划任务实例 - Magento Cron Job Example
- How to automatic process SSAS cube using SQL Server agent job
- How to trigger automatic job by Cron
- magento show cron job list
- magento -- 1.4下的计划任务(cron job)
- magento 2 cronjob setup
- Setting Up Cron Job Using crontab
- Magento模块中添加计划任务Cron Job【magento二次开发】
- Magento 添加计划任务Cron Job
- cron job的方式定时备份Redis的数据文件,并将备份文件copy到安全的磁盘介质中。创建一个定期任务(cron job)
- the env in cron job
- Cronjob setup
- [Python]Import: Using Non-Builtin Functions
- How to Create a Cron Job (Scheduled Task)
- Oracle 10g: Checklist To Diagnose Issues Related To Automatic Run Of Job GATHER_STATS_JOB (Doc ID 80
- Powershell: Launch multiple scripts in parallel using Start-Job
- How to generate Oracle Net tracing for a DBMS_JOB using a database link
- What is a cronjob, and how do I use it?
- sqoop ERROR tool.ImportTool: Error during import: Import job failed!
- Linux cron job 详解