magento xml导入映射 [英] magento xml import mapping

查看:70
本文介绍了magento xml导入映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将xml类别映射到我的magento类别.

I would like to map xml categories to my magento categories.

我整理了可以正常工作的导入脚本,但是它没有导入到magento的任何类别中.

I put together import script which works, but it does not import into any categories in magento.

在脚本即时测试中,我想导入具有xml的产品

In script im testting I would like to import product that has in xml

<izdelekKategorija>Komponente</izdelekKategorija>

变成magento类别编号738.

into magento category number 738.

我正在寻求帮助,我是PHP的初学者.

Im asking for some help Im a beginner in 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
?>

我设法使脚本正常工作,并且可以正常导入,但是无法从url导入图像...

I managed to get script working and it's importing ok, but it does not import images from url...

新的工作代码:

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

推荐答案

我的问题的解决方案是移动

Solution to my question is to move

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

进入foreach循环.

into foreach loop.

这篇关于magento xml导入映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆