2016-01-19 6 views
0

Пользовательский модуль содержит импорт CSV-файла в magento. Я изменил доступность для импорта файла из файла, находящегося внутри. Теперь мне нужно настроить cronjob, ведьма будет импортировать или запустить функцию импорта.Как настроить Magento 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

Вы 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, так как вы не можете передавать ему аргументы из XML-кода crontab Magento.