gpt4 book ai didi

magento - 在 magento 中导出带有产品 ID 的数据流

转载 作者:行者123 更新时间:2023-12-02 18:34:48 26 4
gpt4 key购买 nike

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

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

问候,

法鲁克汗

最佳答案

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

关于magento - 在 magento 中导出带有产品 ID 的数据流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15909742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com