运行 magento 产品导入 cron
Run magento product import cron
我在网上找到了this解决方案,发现了更多类似的解决方案。我需要 运行 一个像这样的配置文件。这是一个自定义产品导入。我想知道的是如何 select 此脚本中的正确 csv 文件?
我通过使用管理产品导入控制器创建前端控制器来完成此操作。然后写了一个脚本调用前端url using php curl.
前端布局xml
<layout version="0.1.0">
<importproduct_cronimport_run>
<remove name="footer" />
<remove name="top.search" />
<remove name="cart_sidebar" />
<remove name="header" />
<remove name="top.menu" />
<remove name="root" />
<reference name="content">
<block type="importproduct/system_convert_run" name="system_convert_run" template="importproduct/cronimport.phtml" output="toHtml" />
</reference>
</importproduct_cronimport_run>
</layout>
前置 phtml 文件
<?php
$this->getProfile()->run();
$array = array("batchId" => $this->getBatchModel()->getId(), "count" => $this->getBatchItemsCount());
$rows = [];
$importData = $this->getImportData();
$arrCounter = 0;
foreach ($importData as $importValue){
$rows[] = $importValue["rows[]"][0];
$arrCounter++;
}
$array["rows"] = $rows;
echo "<br>jsonDataStart{".$this->jsonEncode($array)."}jsonDataEnd";
?>
这是脚本的主要部分。
function importcsv($baseurl,$csv,$logFile){
Mage::log('Start importproduct/cronImport/run',null,'prod_import.log');
$url = $baseurl."importproduct/cronImport/run/id/3/files/".$csv;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
$error = curl_error($curl)."\r\n";
curl_close ($curl);
Mage::log('Print errors if any',null,'prod_import.log');
file_put_contents($logFile, $error, FILE_APPEND | LOCK_EX);
Mage::log('End importproduct/cronImport/run',null,'prod_import.log');
/**** Extract Batch ID and Row IDs ***********/
$jsonDataStart = stripos($result,"jsonDataStart{") + 14;
$jsonDataEnd = stripos($result,"}jsonDataEnd");
$jsonLength = $jsonDataEnd - $jsonDataStart;
$jsonArray = substr($result, $jsonDataStart, $jsonLength);
$simpleArray = json_decode($jsonArray, true);
$batchId = $simpleArray["batchId"];
$totalRecords = $simpleArray["count"];
$rowIdList = $simpleArray["rows"];
for ($x = 0; $x < $totalRecords; $x++) {
/*** call batchRun ***/
Mage::log('Start importproduct/cronImport/batchRun/id/'.$batchId."/row/".$rowIdList[$x],null,'prod_import.log');
$url = $baseurl."importproduct/cronImport/batchRun/";
$post = "batch_id=".$batchId."&rows%5B%5D=".$rowIdList[$x];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
$error = curl_error($curl)."\r\n";
curl_close ($curl);
Mage::log('Print errors if any',null,'prod_import.log');
file_put_contents($logFile, $error, FILE_APPEND | LOCK_EX);
Mage::log('End importproduct/cronImport/batchRun/id/'.$batchId."/row/".$rowIdList[$x],null,'prod_import.log');
}
/*** call batchFinish ***/
Mage::log('Start importproduct/cronImport/batchFinish/id/'.$batchId,null,'prod_import.log');
$url = $baseurl."importproduct/cronImport/batchFinish/id/".$batchId."/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
$error = curl_error($curl)."\r\n";
curl_close ($curl);
Mage::log('Print errors if any',null,'prod_import.log');
file_put_contents($logFile, $error, FILE_APPEND | LOCK_EX);
Mage::log('End importproduct/cronImport/batchFinish/id/'.$batchId,null,'prod_import.log');
/**** Move imported file to directory Imported ****/
if (file_exists("var/import/".$csv)) {
$t=time();
$timestamp = date("Y-m-d-H-i-s",$t);
rename("var/import/".$csv, "var/import/imported/".$timestamp." - ".$csv);
}
}
如果您需要更多详细信息,请发表评论。
我在网上找到了this解决方案,发现了更多类似的解决方案。我需要 运行 一个像这样的配置文件。这是一个自定义产品导入。我想知道的是如何 select 此脚本中的正确 csv 文件?
我通过使用管理产品导入控制器创建前端控制器来完成此操作。然后写了一个脚本调用前端url using php curl.
前端布局xml
<layout version="0.1.0">
<importproduct_cronimport_run>
<remove name="footer" />
<remove name="top.search" />
<remove name="cart_sidebar" />
<remove name="header" />
<remove name="top.menu" />
<remove name="root" />
<reference name="content">
<block type="importproduct/system_convert_run" name="system_convert_run" template="importproduct/cronimport.phtml" output="toHtml" />
</reference>
</importproduct_cronimport_run>
</layout>
前置 phtml 文件
<?php
$this->getProfile()->run();
$array = array("batchId" => $this->getBatchModel()->getId(), "count" => $this->getBatchItemsCount());
$rows = [];
$importData = $this->getImportData();
$arrCounter = 0;
foreach ($importData as $importValue){
$rows[] = $importValue["rows[]"][0];
$arrCounter++;
}
$array["rows"] = $rows;
echo "<br>jsonDataStart{".$this->jsonEncode($array)."}jsonDataEnd";
?>
这是脚本的主要部分。
function importcsv($baseurl,$csv,$logFile){
Mage::log('Start importproduct/cronImport/run',null,'prod_import.log');
$url = $baseurl."importproduct/cronImport/run/id/3/files/".$csv;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
$error = curl_error($curl)."\r\n";
curl_close ($curl);
Mage::log('Print errors if any',null,'prod_import.log');
file_put_contents($logFile, $error, FILE_APPEND | LOCK_EX);
Mage::log('End importproduct/cronImport/run',null,'prod_import.log');
/**** Extract Batch ID and Row IDs ***********/
$jsonDataStart = stripos($result,"jsonDataStart{") + 14;
$jsonDataEnd = stripos($result,"}jsonDataEnd");
$jsonLength = $jsonDataEnd - $jsonDataStart;
$jsonArray = substr($result, $jsonDataStart, $jsonLength);
$simpleArray = json_decode($jsonArray, true);
$batchId = $simpleArray["batchId"];
$totalRecords = $simpleArray["count"];
$rowIdList = $simpleArray["rows"];
for ($x = 0; $x < $totalRecords; $x++) {
/*** call batchRun ***/
Mage::log('Start importproduct/cronImport/batchRun/id/'.$batchId."/row/".$rowIdList[$x],null,'prod_import.log');
$url = $baseurl."importproduct/cronImport/batchRun/";
$post = "batch_id=".$batchId."&rows%5B%5D=".$rowIdList[$x];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
$error = curl_error($curl)."\r\n";
curl_close ($curl);
Mage::log('Print errors if any',null,'prod_import.log');
file_put_contents($logFile, $error, FILE_APPEND | LOCK_EX);
Mage::log('End importproduct/cronImport/batchRun/id/'.$batchId."/row/".$rowIdList[$x],null,'prod_import.log');
}
/*** call batchFinish ***/
Mage::log('Start importproduct/cronImport/batchFinish/id/'.$batchId,null,'prod_import.log');
$url = $baseurl."importproduct/cronImport/batchFinish/id/".$batchId."/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
$error = curl_error($curl)."\r\n";
curl_close ($curl);
Mage::log('Print errors if any',null,'prod_import.log');
file_put_contents($logFile, $error, FILE_APPEND | LOCK_EX);
Mage::log('End importproduct/cronImport/batchFinish/id/'.$batchId,null,'prod_import.log');
/**** Move imported file to directory Imported ****/
if (file_exists("var/import/".$csv)) {
$t=time();
$timestamp = date("Y-m-d-H-i-s",$t);
rename("var/import/".$csv, "var/import/imported/".$timestamp." - ".$csv);
}
}
如果您需要更多详细信息,请发表评论。