2013-05-14 43 views
1

我想讓我的腳本工作。我基本上從CSV導入數據到MySQL,這工作正常。然後,我喜歡將這些數據導入到Maggent中,並將它的具有正確屬性的Datapump API導入到magento中。產品從數據泵API非常緩慢從mysql導入到magento

我的腳本基本上可以工作,但需要大量的時間導入。我認爲這是因爲每次導入都會再次調用API。

<?php 

header('Content-Type: text/html; charset=utf-8'); 

require_once("/volume1/web/bwebshop/magmi/inc/magmi_defs.php"); 
require_once("/volume1/web/bwebshop/magmi/integration/inc/magmi_datapump.php"); 

$host=""; 
$user=""; 
$pw=""; 

$connection=mysql_connect($host, $user, $pw) or die ("Verbindungsversuch fehlgeschlagen"); 

$mysqldb="xxxxx"; // Gewuenschte Datenbank angeben 

mysql_select_db($mysqldb, $connection) or die("Konnte die Datenbank nicht waehlen."); 


mysql_query('SET CHARACTER SET \'UTF8\''); 

$sql = "SELECT d,q FROM test"; 
$result = mysql_query($sql); 


$list = array(); 

while ($row = mysql_fetch_array($result)) { 
$list[] = $row; 




$dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); 
$dp->beginImportSession("categories","create"); 

$item = array("sku"=> $row['q'], "categories"=> $row['d'], "attribute_set"=> "webshop")); 


$dp->ingest($item); 

$dp->endImportSession(); 



} 

我認爲最後四行應該在別的地方。我究竟做錯了什麼?幫助將不勝感激。謝謝。

回答

2

您的項目循環中有$dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");$dp->beginImportSession();$dp->endImportSession();

這些只應在每次導入時調用一次(不適用於每個項目)。嘗試將這些移動到項目循環之外。

喜歡的東西:

$dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport"); 
$dp->beginImportSession("categories","create"); 

while ($row = mysql_fetch_array($result)) { 
    $list[] = $row; 

    $item = array("sku"=> $row['q'], "categories"=> $row['d'], "attribute_set"=> "webshop"));  

    $dp->ingest($item);  
} 

$dp->endImportSession();