Import xml

0

Witam,

ma problem z importem xml do sklepu nie chce mi zrobić drzewa kategorii tylko wrzuca wszystko do jednego poza tym wszytko inne jest ok gdzie może być problem dziękuje za pomoc

taką mam strukturę xml

 <?xml version="1.0" encoding="UTF-8"?>
<offer>
 <item>
  <id>7373</id>
  <brand>EASYCAM</brand>
  <name><![CDATA[EC-523-SDH]]></name>
  <category>Produkty archiwalne/Monitoring</category>
  <price>119</price>
  <images>
    <img>http://media/catalog/product/1/7/1737-3.jpg</img>
    <img>http://media/catalog/product/1/7/1737.jpg</img>
   </images>
  <attributes>
    <attribute name="Rodzaj przetwornika"><![CDATA[CMOS]]></attribute>
    <attribute name="Wielkość przetwornika"><![CDATA[1/3'']]></attribute>
    <attribute name="Ilość linii telewizyjnych"><![CDATA[800 tvl]]></attribute>
    <attribute name="Zasięg reflektora podczerwienii"><![CDATA[15 m]]></attribute>
    <attribute name="Typ kamery"><![CDATA[WEWNĘTRZNA]]></attribute>
    <attribute name="Ogniskowa obiektywu"><![CDATA[3.6mm]]></attribute>
    <attribute name="Mechaniczny filtr podczerwieni "><![CDATA[Tak]]></attribute>
    <attribute name="Wbudowany reflektor podczerwienii"><![CDATA[Tak]]></attribute>
    <attribute name="WDR"><![CDATA[Nie]]></attribute>
    <attribute name="Balans bieli"><![CDATA[Tak]]></attribute>
    <attribute name="Klasa szczelności"><![CDATA[Nie dotyczy]]></attribute>
    <attribute name="Czułość przetwornika"><![CDATA[0 lux]]></attribute>
    <attribute name="2DNR"><![CDATA[Nie]]></attribute>
    <attribute name="3DNR"><![CDATA[Nie]]></attribute>
    <attribute name="DWDR"><![CDATA[Nie]]></attribute>
    <attribute name="HLC"><![CDATA[Nie]]></attribute>
    <attribute name="BLC"><![CDATA[Tak]]></attribute>
    <attribute name="AGC"><![CDATA[Tak]]></attribute>
    <attribute name="Menu OSD"><![CDATA[Nie]]></attribute>
    <attribute name="Zasilanie kamery"><![CDATA[12V]]></attribute>
    <attribute name="Model przetwornika"><![CDATA[CMOS]]></attribute>
  </attributes>
  </item>
<offer>

a tak wygląda to w php

 <?php

class Import extends Products
{
    var $conf_name	          = 'elo';
    var $conf_lang	          = 'pl';
    var $conf_fileaddr		  = '#CONF_LINK#';
	var $conf_no_update_options = true;
    var $conf_required_fields = array('link');
    var $conf_fields_info	  = array('link' => 'Link do pliku XML hurtowni elo.pl (Ceny w brutto.)');
    var $conf_type	          = 'xml';
    var $conf_prices		  = 'brutto';
	var $conf_retail	  = true;
    var $conf_decimal_sep	  = ',';
    var $conf_field_key		  = 'prod_symbol_int';
    var $conf_unit_if_empty       = 'szt.';

    function convert_to_options($arr)
    {
        $options = array();
        foreach($arr as $k => $v) {
            $options[] = array(
                'name'  => $v['n'],
                'value' => sshop_ucfirst($v['v']),
                'type'  => 'info',
            );
        }
        return json_encode($options);
    }

    function conf_parse_file($xml, $cache_json)
    {
        $i=0;
        $prod = new stdClass();
        foreach($xml->item as $k => $v) {
            $opt=array();
            $prod->$i    = new stdClass();
            $prod->$i->id = tostr($v->id);
            $prod->$i->name = tostr($v->name);
            $prod->$i->brand = tostr($v->brand);
            $prod->$i->price = tostr($v->price);

            
            if(!empty($v->attributes)){
                foreach($v->attributes->attribute as $value){
                    $opt[] = array('n'=>tostr($value->attributes()->name),'v'=>tostr($value));
                }
            }
            $prod->$i->options = $this->convert_to_options($opt);

            $prod->$i->images   = array();
            if(is_object($v->images->img)) {
                foreach($v->images->img as $photo) {
                    $prod->$i->images[] = trim(tostr($photo));
                }
            } elseif(!empty($v->images->img)) {
                $prod->$i->images[] = trim(tostr($v->images->img));
            }
            $prod->$i->images = array_filter($prod->$i->images);
            $i++;
        }
        unset($xml);

        $struct = array(
            'products_path'		=> $prod,

            'fields' => array(
                'prod_symbol_int'	=> 'id',
                'prod_name_pl'		=> 'name',
                'prod_cat'		=> 'cat',
                'prod_price'		=> 'price',
                'prod_symbol'		=> 'id',
                'prod_producer'		=> 'brand',
            ),
        );
        return $struct;
    }

    function conf_handle_category($row)
	{
		return array(
			'cats_names'		=> (!empty($row->category)) ? $row->category : '',
			'cats_separator'	=> '/',
		);
	}


    function conf_handle_options($row)
    {
        return !empty($row->options) ? json_decode($row->options, 1) : array();
    }

    function conf_parse_images($row)
    {
        if ( empty($row->images) )
            return array();
        $imgs = $row->images;
        return $imgs;
    }
}
?>
0

moze chodzi o ta linijke?

            if(!empty($v->attributes)){
                foreach($v->attributes->attribute as $value){
                    $opt[] = array('n'=>tostr($value->attributes()->name),'v'=>tostr($value));
                }
            }

a dokladniej

 foreach($v->attributes->attribute as $value){

zmien na

foreach($v->attributes as $value){
}

to taka 1 mysl :) nie mam jak testowac

1 użytkowników online, w tym zalogowanych: 0, gości: 1