使用magento中的产品ID导出数据流

时间:2013-04-09 18:29:52

标签: magento

我正在使用数据流配置文件但是这不允许从magento导出entity_id或产品ID。我们需要将一些再营销代码集成到我无法使用SKU的地方。无论如何都要使用数据流配置文件导出entity_id。

其次,我必须每24小时运行一次数据流配置文件。

此致

Farrukh Khan

1 个答案:

答案 0 :(得分:1)

您可以从以下网址获取帮助以导出产品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','');
?>