2015-08-15 116 views
1

我想将xml类别映射到我的magento类别。magento xml导入映射

我把放在一起的导入脚本放在一起,但它不会导入到magento的任何类别中。

在脚本IM试井我想导入已在XML

<izdelekKategorija>Komponente</izdelekKategorija> 

到Magento的类别数738

林寻求一些帮助林在PHP初学者的产品。

谢谢。

<?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 
?> 

编辑:我设法得到脚本的工作,它的进口确定,但它不会从网址导入图片...

新的工作代码:

<?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 
?> 
+0

当您设法回答关于类别的问题时,您可能应该不更新您的问题,而是制定一个解释解决方案以及原因的答案。然后你可以问一个新的问题,因为你现在的问题是不同的(你可以将你的新问题链接到前一个问题,给它一些上下文)。这对于问答网站很重要,因为我们为*未来*访问者收集问题*和*答案,以便其他人可以从我的问题和答案中受益。 – hakre

回答

0

解决我的问题是移动

$izdelek = ((string)$item->izdelekKategorija); 
$kategorija = (($spisekKategorij[$izdelek]) ? $spisekKategorij[$izdelek] : $kategorija); 

到foreach循环。

+0

也请写下为什么前面的代码在问题中不起作用,所以推动代码的理由变得清晰。只要放下代码就好了。感谢您将评论考虑在内,不要忘记编辑问题,并缩短其中的文本(编辑后的部分:现在似乎是新的问题)。 – hakre