magmi-git
magmi-git copied to clipboard
Insert in datapump
Hello, I would like create a special inserts in database and I create code in datapump, but the sentence this->tablename and this->insert doesn't work.
Can I help me?
This is my code:
<?php
require_once("../../inc/magmi_defs.php");
require_once("../inc/magmi_datapump.php");
/**
* Define a logger class that will receive all magmi logs *
*/
class TestLogger
{
public function log($data, $type)
{
echo "$type:$data\n";
}
}
$dp = Magmi_DataPumpFactory::getDataPumpInstance("productimport");
$dp->beginImportSession("default", "create", new TestLogger());
$file ='myfile.csv'; // absolute path
$fila = 0;
if (($fichero = fopen($file, "r")) !== FALSE) {
while (($datos = fgetcsv($fichero, 1024)) !== FALSE) {
if($fila >=1){
$newProductData = array(
'category_ids' => $datos[0],
'name' => $datos[1],
'description' => $datos[2],
'short_description' => $datos[3],
'sku' => $datos[4],
'price' => $datos[5],
'tax_class_id' => "None",
'is_in_stock' => 1,
'qty' => $datos[6],
'weight' => $datos[7],
'ean' => $datos[8],
'fabricante' => $datos[9],
'type_id' => 'simple',
'meta_title' => $datos['1'],
'meta_keyword' => $datos[1].', '.$datos[9],
'meta_description' => $datos[2]
);
$newProductData['image']='+'.$datos[10]; // + show picture, - dont show picture
$newProductData['small_image']='+'.$datos[10]; // small img
$newProductData['thumbnail']='+'.$datos[10];
$res = $dp->ingest($newProductData);
if($res['ok'] === TRUE){
$pid = $res['_product_id'];
$mp_product = $this->tablename("marketplace_product");
$sql = "INSERT INTO $mp_product ('megaproductid, userid, status') VALUES (?,?,?)";
$data = array($pid, 36, 2);
$this->insert($sql, $data);
echo '' . ' mem:'.memory_get_usage().'-'.$pid.'-'." ... Done! <br />\n"; //memory usage check
$newProductData=null; //clear memory
unset($newProductData); //clear memory;
} else
{
throw new Exception( "Magmi error: " . $res["_exception_message"] );
}
}
$fila++;
}
fclose($fichero);
}
$dp->endImportSession(); // end import