自定义模块包含以magento导入CSV文件。我已经更改了从内部文件导入文件的可用性。现在我需要设置一个cronjob女巫将导入或运行导入功能。
请查看下面的代码,并与config.xml文件进行比较是否正确。
app/code/community/Vehence/Exporter/Model/Importorders.php
class Vehence_Exporter_Model_Importorders extends Mage_Core_Model_Abstract
{
public $order_info = array();
public $order_item_info = array();
public $order_item_flag = 0;
public $store_id = 0;
public $import_limit = 0;
public function readCSV($csvFile,$data)
{
$this->import_limit = $data['import_limit'];
$this->store_id = $data['store_id'];
$file_handle = fopen('number1.csv', 'r'); //fopen($csvFile, 'r');
$i=0;
$decline = array();
$available = array();
$success = 0;
$parent_flag = 0;
$invalid = 0;
$line_number = 2;
$total_order = 0;
Mage::helper('exporter')->unlinkFile();
Mage::helper('exporter')->header();
while (!feof($file_handle) )
{
$line_of_text[] = fgetcsv($file_handle);
if($i!=0)
{
if($line_of_text[$i][0]!='' && $parent_flag==0)
{
$this->insertOrderData($line_of_text[$i]);
$parent_flag = 1;
$total_order++;
}
else if($line_of_text[$i][91]!='' && $parent_flag == 1 && $line_of_text[$i][0]=='')
{
$this->insertOrderItem($line_of_text[$i]);
}
else if($parent_flag==1)
{
try
{
$message = Mage::getModel('exporter/createorder')->createOrder($this->order_info,$this->order_item_info,$this->store_id);
Mage::getModel('exporter/createorder')->removeOrderStatusHistory();
} catch (Exception $e) {
Mage::helper('exporter')->logException($e,$this->order_info['increment_id'],'order',$line_number);
Mage::helper('exporter')->footer();
$decline[] = $this->order_info['increment_id'];
$message = 0;
}
if($message== 1)
$success++;
if($message== 2){
Mage::helper('exporter')->logAvailable($this->order_info['increment_id'],'order',$line_number);
Mage::helper('exporter')->footer();
$decline[] = $this->order_info['increment_id'];
}
$this->order_info = array();
$this->order_item_info = array();
$this->order_item_flag = 0;
$this->insertOrderData($line_of_text[$i]);
$parent_flag = 1;
$line_number = $i+1;
$total_order++;
}
}
$i++;
if($this->import_limit < $total_order)
break;
}
$isPrintable = Mage::helper('exporter')->isPrintable();
if($success)
Mage::getModel('core/session')->addSuccess(Mage::helper('exporter')->__('Total '.$success.' order(s) imported successfully!'));
if($decline || $isPrintable)
Mage::getModel('core/session')->addError(Mage::helper('exporter')->__('Click <a href="'.Mage::helper("adminhtml")->getUrl("exporter/adminhtml_exporter/exportLog").'">here</a> to view the error log'));
fclose($file_handle);
return array($success,$decline);
}
这是config.xml文件:
<crontab>
<jobs>
<vehence_importorders>
<schedule><cron_expr>0 1 * * *</cron_expr></schedule>
<run><model>importorders::readCSV</model></run>
</vehence_importorders>
</jobs>
</crontab>
答案 0 :(得分:0)
您的config.xml文件只需要一个小的更新:
<crontab>
<jobs>
<vehence_importorders>
<schedule><cron_expr>0 1 * * *</cron_expr></schedule>
<run><model>vehence_exporter/importorders::readCSV</model></run>
</vehence_importorders>
</jobs>
</crontab>
您可能还发现需要更新readCSV函数,因为您无法从Magento的crontab XML传递参数。