2015-08-15 118 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