I would like to map xml categories to my magento categories.
I put together import script which works, but it does not import into any categories in magento.
In script im testting I would like to import product that has in xml
<izdelekKategorija>Komponente</izdelekKategorija>
into magento category number 738.
Im asking for some help Im a beginner in PHP.
Thank you.
<?php
$kat = array(
'Komponente' => '738',
);
class TestLogger
{
/**
* logging methos
*
* @param string $data
* : log content
* @param string $type
* : log type
*/
public function log($data, $type)
{
echo "$type:$data\n";
}
}
// setup include PATH's
set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines');
// end include PATH's
require_once("magmi_datapump.php"); // call Datapump
$dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");
$dp->beginImportSession("123", "create", new TestLogger()); // default- name of profile , create - we want to create and update items
$file="test.xml";
$microline = new SimpleXMLElement($file, null, true); // load XML
$izdelek = array ((string)$item->izdelekKategorija);
global $kat;
$izdelek = array ((string)$item->izdelekKategorija);
$kategorija = (isset($kat[$izdelek]) ? $kat[$izdelek] : $kategorija);
foreach ($microline as $item){
$newProductData = array(
"sku" => (string)$item->izdelekID .=' inbbt',
"name" => (string)$item->izdelekIme, // name
"attribute_set" => "test", // attribute_set
"store" => "test",
"category_ids" => $kategorija,
"tax_class_id" => "3",
);
$dp->ingest($newProductData);
echo '' . ' mem:'.memory_get_usage() . " ... Done! <br />\n"; //memory usage check
$newProductData=null; //clear memory
unset($newProductData); //clear memory
}
unset($microline);
$dp->endImportSession(); // end import
?>
Edit: I managed to get script working and it's importing ok, but it does not import images from url...
New working code:
<?php
$spisekKategorij = array(
'Komponente' => '738',
'Prenosniki' => '742',
'Monitorji' => '737',
);
class TestLogger
{
/**
* logging methos
*
* @param string $data
* : log content
* @param string $type
* : log type
*/
public function log($data, $type)
{
echo "$type:$data\n";
}
}
// setup include PATH's
set_include_path('magmi' . PATH_SEPARATOR . 'magmi/inc' . PATH_SEPARATOR . 'magmi/integration/inc' . PATH_SEPARATOR . 'magmi/engines');
// end include PATH's
require_once("magmi_datapump.php"); // call Datapump
$dp=Magmi_DataPumpFactory::getDataPumpInstance("productimport");
$dp->beginImportSession("123", "create"); // default- name of profile , create - we want to create and update items
$file="test.xml";
$microline = new SimpleXMLElement($file, null, true); // load XML
// $kategorija = $izdelek;
// $kategorija = (isset($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija);
foreach ($microline as $item){
$izdelek = ((string)$item->izdelekKategorija);
$kategorija = (($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija);
$newProductData = array(
"sku" => (string)$item->izdelekID .=' abbt',
"name" => (string)$item->izdelekIme,
'price' => ((real)$item->cenaBrezddv),
'description' => (string)$item->izdelekOpis . (string)$item->izdelekDodatenOpis,
'short_description' => (string)$item->izdelekDodatenOpis,
'diagonala_rshop' => (string)$item->velikost_zaslona,
'procesor_rshop' => (string)$item->procesor,
'ram_rshop' => (string)$item->ram,
'hdd_rshop' => (string)$item->disk,
'operacijski_rshop' => (string)$item->licencna_nalepka,
'locljivost_rshop' => (string)$item->locljivost,
'grafika_rshop' => (string)$item->grafika,
"attribute_set" => "test",
"store" => "rshop",
"category_ids" => $kategorija,
);
$newProductData["image"]='+'.(string)$item->slike->slika1; // + show picture, - dont show picture
$newProductData['small_image']='+'.(string)$item->slike->slika1; // small img
$newProductData['thumbnail']='+'.(string)$item->slike->slika1;
echo $izdelek;
echo $kategorija;
echo $slika;
echo '<pre>'; print_r($newProductData); echo '</pre>';
$dp->ingest($newProductData);
echo '' . ' mem:'.memory_get_usage() . " ... Done! <br />\n"; //memory usage check
$newProductData=null; //clear memory
unset($newProductData); //clear memory
}
unset($microline);
$dp->endImportSession(); // end import
?>