Karolin Bierbrauer
Karolin Bierbrauer

Reputation: 89

product import into magento from mysql with datapump api very slow

I am trying to get my script working. I basically import data from a CSV into mysql, which works fine. I then like to take this data and import it with Magmi and its Datapump API with the right attributes into magento.

My script basically works but it takes an awful lot of time importing. I think it is because the API gets called again with every import.

<?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();



}  

I think the last four rows should be somewhere else. What am I doing wrong? Help would be appreciated. Thanks.

Upvotes: 1

Views: 935

Answers (1)

Axel
Axel

Reputation: 10772

You have $dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");, $dp->beginImportSession(); and $dp->endImportSession(); within your item loop.

These should only be called once per import (not for each item). Try moving these outside of your item loop.

Something like:

$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();

Upvotes: 2

Related Questions