XML TO CSV issue

Hello,



We are getting products list from the suppliers in XML.We’re converting XML’s to CSV’s but we need to change the format of CSV before importing it.



What I mean, in XML, we have 2 columns 1 is for category of the product the other one is for the subcategory.But, we need to have in this format according to the cs-cart csv documents books///computers instead books,computers.



There is a delimiter field in the back-end,can we make it empty? or anything we can do from there?



Manually,creating a new column named category and writing books///computers then converting to csv is a solution but we have many suppliers and xml’s we are trying to make this process more automated.



We have same problem for product features,product options.We have a color column in xml’s but it is not in cs-cart format as well.



Do we need writing some Excel macro to automate this process.Any better idea?



Thank you,

Anyone to help?

Go research XSLT. You should be able to do your transformation of the data that way. Then you could use whatever you are using to translate the xml to csv. Note that xml does not have columns, it is mult-dimensional (hierachial).



Why not just read in your XML into a PHP program and write out the CSV format you want? It’s probably about 20 lines of code if you know what your input is like and what output you want.

Thanks for your answer.


  1. But the problem is : XML’s are coming in a different scheme and have different column names like one of them called price as " list price" other one called “_price” etc.


  2. Also, our suppliers are from different sectors,so it is difficult to determine the input fields.For example,ISBN field is a unique for only suppliers selling books,some of them has only thumbnails while the others have small and big images together.


  3. Is it simple to add new imported fields for csv import.Instead of using product features,do you suggest us to use new created fields?Since,for ISBN,we need to revise the coming XML’s according to cs-cart format.



    4.Is it difficult to write XML import tool for Cs-Cart.Assume that all xml’s input fields are same or/and we edit them manually to have only 1 input/.Is it easy to import that XML and create necessary fields for import?



    Thank you,

[quote name=‘getreal’]Thanks for your answer.


  1. But the problem is : XML’s are coming in a different scheme and have different column names like one of them called price as " list price" other one called “_price” etc.

    [/quote]

    That’s what you should be using XSLT for, to normalize the input to something you can work with.


[quote]

2. Also, our suppliers are from different sectors,so it is difficult to determine the input fields.For example,ISBN field is a unique for only suppliers selling books,some of them has only thumbnails while the others have small and big images together.

[/quote]

I thought you originally asked how to convert various XML input feeds to something common that you could ultimately end up with a CSV. What you are describing it something that takes some analysis, design and coding. You’re not going to find anything out of the box (other than a 3rd party drag-n-drop XML/XSL editor for a few hundered $$) that will do what you want.


[quote]

3. Is it simple to add new imported fields for csv import.Instead of using product features,do you suggest us to use new created fields?Since,for ISBN,we need to revise the coming XML’s according to cs-cart format.

[/quote]

I chose to make it a merchant’s decision in my XML Data Feeds addon (does output, not input) whether to use a field from the products table, a product feature or a literal value.


[quote]

4.Is it difficult to write XML import tool for Cs-Cart.Assume that all xml’s input fields are same or/and we edit them manually to have only 1 input/.Is it easy to import that XML and create necessary fields for import?



Thank you,[/QUOTE]

Easy is a relative term. It’s a project that requires thought, design, implementation and testing. Personally, I’d prefer to read the XML in and use PHP to extract/adjust the fields to create the “common format”. But this is simply because I’m more comfortable with PHP than I am with XSLT. But XSLT was designed to normalize input, read the data and generate XML output. Most of the custom imports I’ve written use one input format. So the key is to have step 1 create the data in a common format and have step 2 do the actual import of data.

Thanks for your detailed explanations Tbirnseth,



We have 1 more question:

How can we import only new products? Assume that csv file has 100 products and we’ve imported all of them and change/edit them according to our needs.Then,the same supplier distribute 30 products more and sent us the csv file including all 1030 products and that 30 products are not added at the end of the spreadsheet.



We cannot find that new products,so we will import the whole csv file,but,because of the product code,the old revised products will be lost.How can we prevent this problem and only importing new products?



Thank you,

I believe there are some php hooks in the import process that would allow you to lookup a product code before the import processing was done. If it exists, you would/could skip it, if not, you could let it go.



The import/export area is fairly arcane in cs-cart. It works well and is extensible but it is also rather sensitive and designed around basic operations.



Why are the revised products lost? Do you mean that changes you’ve made after importing are overwritten? Then yes, that would be the expected (and desired) behavior.

Yes.that’s the question.



I’m asking how can I prevent these products are overwritten since their product codes will be same? or how can I only import new products while importing?



Thanks,

As I said, I believe there is a pre-processing hook in the EXIM code that will let you do that kind of check at the start of processing for every record.

So, you’re suggesting us to play with that EXIM codes or that’s the cs-cart default behavior.



We have tried to import the product having a same product code ,Cs-Cart didn’t ask us to overwrite or not ? also not skipped and it overwrote the product with the new one.!



Thanks,

I think at this point you should get yourself a developer who understands what I mean when I say there is a hook in the EXIM code that will allow you to do preprocessing of a record.