3

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

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

问候,

法鲁克汗

4

1 回答 1

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','');
?>
于 2015-08-21T20:18:49.277 回答