Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Making Magento supported CSV file
 
halaac
Jr. Member
 
Total Posts:  14
Joined:  2009-05-28
 

Hello.

I’m trying to import products to Magento.
My program gives me an XML file that looks like that:

<?xml version="1.0" encoding="UTF-8"?>
<КоммерческаяИнформация ВерсияСхемы="2.03" ДатаФормирования="2009-06-09">
<Классификатор>
<Ид>3533e361-3794-11dd-b281-001a928f9bb0</Ид>
<Наименование>Классификатор (Каталог товаров)</Наименование>
<Группы>
<Группа>
<Ид>f4389d07-46aa-11dd-b28c-001a928f9bb0</Ид>
<Наименование>Virtuves moduli</Наименование>
<Группы>
<Группа>
<Ид>8e97f949-fe9f-11dd-9f7d-0018fefa1410</Ид>
<Наименование>Silver</Наименование>
</Группа>
</Группы>
</Группа>
</Группы>
</Классификатор>
<Каталог>
...
So i wrote a php script that makes XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product>
<store>admin</store>
<website>base</website>
<attribute_set>Default</attribute_set>
<type>Simple</type>
<sku>287afdc2-ca6f-11dd-bd4f-0018fefa1410</sku>
<category_ids>40</category_ids>
<name>Silver D11 60 virtuves skapītis</name>
<weight>14</weight>
<price>44.71</price>
<description>Skapisha apraksts </description>
<short_description>Skapisha apraksts </short_description>
<status>Enabled</status>
<tax_class_id/>
<visibility>Catalog, Search</visibility>
<qty>9</qty>
</product>
</products>

But I can’t import this XML file, becouse Magento needs CSV or MSXML file.
So I tried to convert it to CSV:
<?php
if (file_exists('sakartots.xml')) {
$xml = simplexml_load_file('sakartots.xml');
} else {
exit('Failed to open import.xml.');
}
$f = fopen('products.csv', 'w');
foreach ($xml->product as $product) {
fputcsv($f, get_object_vars($product),',','"');
}
fclose($f);
?>
But I got CSV file without first line as field names.
Can anyone help me? Give some ideas

 
Magento Community Magento Community
Magento Community
Magento Community
 
edmondscommerce
Guru
 
Avatar
Total Posts:  342
Joined:  2008-08-26
 

just create a header line as an array manually and write that out before starting your foreach loop

I suspect though you are starting a long hard path here. I would try manually creating your CSV file format first and then trying to import to Magento to see if the idea will even work before you put too much effort into converting this XML to CSV

 
Magento Community Magento Community
Magento Community
Magento Community
 
halaac
Jr. Member
 
Total Posts:  14
Joined:  2009-05-28
 

May you suggest a better way to import from this xml file?

 
Magento Community Magento Community
Magento Community
Magento Community
 
halaac
Jr. Member
 
Total Posts:  14
Joined:  2009-05-28
 

Some results.
I tried to import my csv (same as it was) using magento import and field mapping.
And it worked.
I was importing only one product.
Now I will try to import more products.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top