2013-04-09 45 views
3

我正在使用數據流配置文件,但這不允許從magento導出entity_id或產品ID。這是我們需要將一些再營銷代碼集成到我無法使用SKU的地方。無論如何,用數據流配置文件導出entity_id。使用magento中的產品ID導出數據流

其次,我必須每24小時運行一次數據流配置文件。

問候,

法魯克汗

+0

我已經工作了,在這裏回答了這個問題,因爲這是在那裏Magento的問題屬於: http://magento.stackexchange.com/questions/32915/dataflow-export-product-entity-id/32916 #32916 – 2014-08-20 11:11:34

回答

0

您可以從以下網址的幫助下,出口產品ID http://www.vuleticd.com/2013/01/27/export-product-ids-with-magento-dataflow-advanced-profiles/

要運行數據流的個人資料,你必須配置腳本來運行,每24個小時。

使用以下代碼,您只需更改profileId & csv文件名。

<?php 
require_once 'app/Mage.php'; 

umask(0); 

Mage::app(); 

$profileId = 7; //put your profile id here 
$filename = "cronimport.csv"; //file needs to be present in var/import directory 

if (!isset($filename)) { 
    die("No file has been set!"); 
} 

$logFileName= $filename.'_'.date('m_d_Y h_i_s_a', time()).'.log'; 

$recordCount = 0; 

Mage::log("Import Started",null,$logFileName); 

$profile = Mage::getModel('dataflow/profile'); 

$userModel = Mage::getModel('admin/user'); 
$userModel->setUserId(1); 
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()) 
    { 
     //@mail('EMAIL_ADDRESS','Cron started','Test',''); 

     $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); 
//@mail('YOUR EMAIL','Cron Ended','Test',''); 
?> 
相關問題