25 replies [Last post]
Francois's picture
Offline
Joined: 08/19/2008
Juice: 387
Was this information Helpful?

Is there a good tutorial somewhere on working with XML product importing in Ubercart? I've been busting my chops trying to get it right, but it's just not working.

--------
'Twas the end of the world, and you didn't even know it.

Francois's picture
Offline
Joined: 08/19/2008
Juice: 387
Lack of flow...

There doesn't seem to be a lot of activity on this forum...

Well, for whoever is interested -> I wasn't able to load the XML data of my products without 'unique_hash'es. Once I added these they loaded fine. I'm not sure whether a unique hash is required - but it doesn't seem like something I can just "cook-up". So, for anyone who struggles you can go here -> http://gdataonline.com/makehash.php <- to create 'unique_hash'es for your products individually. It is a bit of a pain if you have a large catalogue; but I've found no better way of doing it.

Creating XML data from an Excel Spreadsheets is also relatively simple -> If anyone is interested I'll pass the tip along.

--------
'Twas the end of the world, and you didn't even know it.

TR
TR's picture
Online
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Francois wrote:There doesn't
Francois wrote:

There doesn't seem to be a lot of activity on this forum...

Don't you think it's a little unreasonable to complain about inactivity, less than 6 hours after your original post?

In any case, if you Search this site for "XML Import" there are quite a few threads that discuss the issue, including what the unique hash is and how to calculate it. There is also an XML schema posted showing you which fields are required and which aren't. That said, this information is scattered all around the site and it would be nice if someone (you?) could bring it together and create a Book page under the documentation section that describes the process in detail.

It would be great if you could report any bugs you found, so that they can be identified and fixed.

<tr>.
Francois's picture
Offline
Joined: 08/19/2008
Juice: 387
Huh?

6 hours? It felt like days. I haven't posted here much, so I have no idea what the usual response time is.

As far as documenting the step by step - I'm most definitely doing that. This is a great feature if I could get it to work.

Bugs - if I found any I would obviously report them -> the only problem is, since I'm not exactly sure how it's meant to work I'm not always sure whether there's a bug or whether it's just my XML that's screwy.

--------
'Twas the end of the world, and you didn't even know it.

sanstey's picture
Offline
Joined: 08/04/2008
Juice: 5
XML import

Hi Francois,

Just to give you an update, I have done some work on the uc_importer module and have it mostly running under D6.
Once I have tested it on my own uploads, I will send you the code and you can test it further.

I get the impression you are like me and would like it to work without having to hand code SQL statements =) Hopefully it will be sorted by the end of this week, although I need to check with spydor as he is in charge of the upgrade.

Stewart Anstey
Newcastle, Australia

Stewart Anstey
Newcastle, Australia

giorgio79@drupal.org's picture
Offline
Joined: 02/02/2008
Juice: 280
Re: XML import

Actually, I myself gave a try to the node_import module with the ubercart product extension, and it works fantastically.

Imported everything, even image db entries!! Fantastic stuff Laughing out loud

edmonkey's picture
Offline
Joined: 09/21/2008
Juice: 2
Mapping extra fields

How did you map the price while importing to the UC price field?

(Views can see all the available fields ok; price, etc)

using drupal 5.10, UC and node_import-5.x-1.6

<<
This answers my question:
http://www.ubercart.org/contrib/5221

uc_product.inc is the support file for node_import

zeezhao's picture
Offline
Joined: 04/23/2008
Juice: 969
Re: Re: XML import

Hi giorgio79. Please let me know what kind of performance you got with the loads and what you did to make it run faster. Thanks.

claye's picture
Offline
Joined: 08/29/2008
Juice: 13
Interested

Could you post your tip? It would be very appreciated as I'll have loads of Products in an Excel sheet next week to import. Thanks in advance!

Francois's picture
Offline
Joined: 08/19/2008
Juice: 387
Excel to XML export.

Hi Claye, sorry but I've been travelling and forgot to check back on this post. Not sure if you still need it, but I'll post it anyway.

  1. Create 2 products in Ubercart. (You will need 2 to create an XML map for Excel.)
  2. Export using http://www.yoursite.com/admin/store/products/export
  3. Using the UCBrowser select a category.
  4. Select the products in the "Select a Product" pane by double clicking on them individually.
  5. Click Export - the file will be saved to your default download location ex. Desktop as -exmaple-tmp-php-uc_export.xml
  6. Open your xml file in a XML editor as UTF-8 for cleanup - the file is exported with no line breaks. On my Mac I use the open source XML Spear.
  7. (Note: Excel seems to have trouble with complex XML - you can experiment to see if you can get more than single depth data per product.)
  8. Once you've clean up your XML you can follow the following tutorial on Youtube to prepare and export your data from Excel to XML. - Convert Excel Spreadsheet data to XML

EXAMPLE XML:

<?xml version="1.0" encoding="utf-8"?>
<store xmlns="http://www.ubercart.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ubercart.org http://www.ubercart.org/files/store.xsd">
   <vocabularies>
      <vocabulary>  <!-- NOTE: Adds Vocabulary or Uses your existing Vocabulary - depending on whether it exists or not -->
         <id>1</id>
         <name>Catalog</name>
         <description/>
         <relations>0</relations>
         <hierarchy>2</hierarchy>
         <multiple>1</multiple>
         <required>0</required>
         <tags>0</tags>
         <weight>0</weight>
         <nodes>Trousers</nodes>
         <nodes>product</nodes>
      </vocabulary>
   </vocabularies>
   <categories>  <!-- NOTE: Adds Category or Uses your existing Category - depending on whether it exists or not -->
      <category>
         <id>1</id>
         <vid>1</vid>
         <name>Trousers</name>
         <description>Trousers</description>
      </category>
   </categories>
   <classes> <!-- NOTE: Adds Classes or Uses your existing Classes - depending on whether it exists or not -->
      <class>
         <id>Trousers</id>
         <name>Trousers</name>
         <description>Two Legged Apparel</description>
      </class>
   </classes>
   <products>

      <product> <!-- NOTE: This indicates the beginning of product 1 -->
         <unique_hash>cba7757acb241509ff360a155951453a</unique_hash> <!-- NOTE: Some argue that you don't need this. I found it worked better if each product had a unique hash. You can make these up. They have to be 32 characters long but can be sequential if you want. Ex. mycollection00000000000000000001 and mycollection00000000000000000002 etc. as long as they're unique. -->
         <id>4</id> <!-- NOTE: You can remove this line if you want. Drupal will create a new ID anyway -->
         <type>trousers</type>
         <name>Product 1</name>
         <description>Denim with long legs</description>
         <model>G0087</model> SKU #
         <list_price>100</list_price>
         <cost>100</cost>
         <sell_price>200.00</sell_price>
         <default_qty>1</default_qty>
         <shippable>1</shippable>
         <image>
            <path>http://localhost:8888/localhost/clothingrus/files/col_4_1.jpg</path>
            <alt>Denim with long legs</alt>
            <title>Product 1</title>
         </image>
      </product>

      <product> <!-- NOTE: This indicates the beginning of product 2 -->
         <unique_hash>cba7757acb241509ff360a155951453a</unique_hash> <!-- NOTE: Some argue that you don't need this. I found it worked better if each product had a unique hash. You can make these up. They have to be 32 characters long but can be sequential if you want. Ex. mycollection00000000000000000001 and mycollection00000000000000000002 etc. as long as they're unique. -->
         <id>5</id> <!-- NOTE: You can remove this line if you want. Drupal will create a new ID anyway -->
         <type>trousers</type>
         <name>Product 2</name>
         <description>Denim with short legs</description>
         <model>G0085</model> SKU #
         <list_price>100</list_price>
         <cost>100</cost>
         <sell_price>200.00</sell_price>
         <default_qty>1</default_qty>
         <shippable>1</shippable>
         <image>
            <path>http://localhost:8888/localhost/clothingrus/files/col_4_1.jpg</path>
            <alt>Denim with long legs</alt>
            <title>Product 1</title>
         </image>
      </product>

   </products>
</store>
<!-- You will find other <tags></tags> keep those you'll use and discard those you won't.
With Single Depth Data I mean:
<product>
   <data></data>
   <data></data>
   <data></data>
</product>
In the above example you'll see that images has a larger depth. Excel might have problems exporting this, but you can experiment and see if you can get it to work.
-->

Things to Remember

  1. The XML tags must stay in the order they were exported to import correctly into Ubercart. The Ubercart XML schema description is here
  2. Since Ubercart requires a specific order of tags your Excel spreadsheet's columns will need to be in that specific order as well.
  3. XML is very sensitive - case sensitive, order sensitive etc. Make sure everything is 100% perfect.

What you'll need to import the data into XML

<!-- Copy your XML file and remove everything until you're left with only something like the following (This will be your XML Map for Excel from now on - Save it somewhere! -->
<?xml version="1.0" encoding="utf-8"?>
<store>
   <products>
      <product>
         <unique_hash>cba7757acb241509ff360a155951453a</unique_hash>
         <type>trousers</type>
         <name>Product 1</name>
         <description>Denim with long legs</description>
         <model>G0087</model> SKU #
         <list_price>100</list_price>
         <cost>100</cost>
         <sell_price>200.00</sell_price>
         <default_qty>1</default_qty>
         <shippable>1</shippable>
         <image>
            <path>http://localhost:8888/localhost/clothingrus/files/col_4_1.jpg</path>
            <alt>Denim with long legs</alt>
            <title>Product 1</title>
         </image>
      </product>
      <product>
         <unique_hash>cba7757acb241509ff360a155951453a</unique_hash>
         <id>5</id>
         <type>trousers</type>
         <name>Product 2</name>
         <description>Denim with short legs</description>
         <model>G0085</model> SKU #
         <list_price>100</list_price>
         <cost>100</cost>
         <sell_price>200.00</sell_price>
         <default_qty>1</default_qty>
         <shippable>1</shippable>
         <image>
            <path>http://localhost:8888/localhost/clothingrus/files/col_4_1.jpg</path>
            <alt>Denim with long legs</alt>
            <title>Product 1</title>
         </image>
      </product>
   </products>
</store>

<!-- After the export from Excel copy <products>...</products> back into the original cleaned up XML file (the first version not the cleared XML Map version) effectively replacing the original -->

IMPORTANT NOTE: Excel for Mac (2008 or earlier) can not do this. You will need a Windows copy. Sad

Importing the Excel Data
This is as easy going to http://www.yoursite.com/admin/store/products/import selecting the file and clicking "Okay."
Note: Depending on the size of your XML file this can take a good long time Shocked
Images will have to be copied by hand (mouse, or input device of choice) to the folder specified in path.

And that's it.

RECAP

  1. Export
  2. Cleanup using XML editor
  3. Prep for Excel Map
  4. Follow instructions from Youtube
  5. Copy and Paste Products
  6. Import

Eye-wink

--------
'Twas the end of the world, and you didn't even know it.

wolfderby@drupal.org's picture
Offline
Joined: 10/14/2008
Juice: 6
Step 7

Complex XML doesn't make sense for bulk processing and importing of data/products because it's complicated Eye-wink

Excel can't save "lists of lists"

If you apply attributes or categories to products and then export the xml file, opening it in excel as a list will give you tables within tables or lists within lists.

You can see these if you go to

Data > XML > XML Source

If you try to save the file it's not exportable. If you remove the other elements by right clicking each tree and hitting remove you essentially clean them up. (You must save as data not spreadsheet)

You'd also then have you remove a bunch of "ns1:"s and one "ns1".

(Note: Excel seems to have trouble with complex XML - you can experiment to see if you can get more than single depth data per product.)

What if we flatten the xml schema maybe in the xsd file and probably in the module too?

Basically attributes and categories need to be columns not rows.

james4fl's picture
Offline
Joined: 02/02/2010
Juice: 2
Fatal Error

I tried to export my 2 products and I get a Fatal Error:

Fatal error: Call to undefined function ubrowser() in /home/os2010/public_html/sitedomain.net/home/modules/uc_importer/uc_importer.module on line 315

Any Ideas what may be causing this or what I can do to correct it?

BTW: I got uc_importer for Durpal 6.x Get it Here: http://drupal.org/files/issues/uc_importer.zip

sanstey's picture
Offline
Joined: 08/04/2008
Juice: 5
XML Import

Francois,

You are right to ask, the importer is not as straight forward as it makes out to be!
I have looked at the importer module code and there are a few problems that need addressing (eg fails when certain XML nodes are not present).
I am working on some fixes that I hope to have done by Monday. I am also going to try to update the importer code to run on Drupal 6.

Regards,

Stewart Anstey
Newcastle, Australia

Francois's picture
Offline
Joined: 08/19/2008
Juice: 387
Awesome

Stewart, that's great. Can't wait.

--------
'Twas the end of the world, and you didn't even know it.

giorgio79@drupal.org's picture
Offline
Joined: 02/02/2008
Juice: 280
tip

Hi,

You probably wont find a one size fits all import module for Drupal, because you can add so many things on to a node, even the default product node. I will be adding to it freetagging etc.

For this reason, the best if you first build a node prototype, and in the end you turn on the devel module and create a test content item. Once done you take a note of all the inserts / updates Drupal is doing which queries get captured by devel.

After that you write your own php mysql insert script.

This weekend I just migrated a massive site with 300 000 nodes, and 2 200 000 million terms with this method... Probably will write it up for Drupal forum as well. Laughing out loud

And now I am on to creating a massive store with Ubercart Smiling

marcellod's picture
Offline
Joined: 02/12/2009
Juice: 5
Ubercart Import/Export

Hello,

When I visit

http://www.yoursite.com/admin/store/products/export

It defaults to a list of my products with no place to choose a file to import?

Am I missing a particular module to allow import/export?

I am using drupal 6.9 with latest version of ubercart.

How can I enable this functionality?

Thanks.

snepa's picture
Offline
Joined: 01/15/2009
Juice: 38
XML export

Attempting to follow Francois' protocol - I had the same experience as marcellod. Also Drupal 6.9 and Ubercart 2.

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Re: XML export

uc_importer is not included yet (Ubercart 2.0-beta5) as far as I can tell. Which is why the admin/store/products/import and admin/store/products/export actions do not resolve to anything else than admin/store/products.

I haven't looked into to the roadmap for Ubercart 2.0, so I can't tell you if this is left out for good, or if the good people from Ubercart just haven't got around to porting it yet. They are releasing new stuff at great speed, so I guess they are working pretty hard Laughing out loud

I need this module for Ubercart 2 as well so I started looking into porting it yesterday - not gooing all that great yet, but will let you know if I succeed Smiling

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Re: Re: XML export

I am afraid that I have run into a dead end with upgrading to Drupal 6 Sad

It seems that the uc_importer module relies heavily on a 'xml_importer' hook to do the actual import work for the various data-types, e.g.:

  module_invoke_all('xml_importer', 'vocabulary', taxonomy_get_vocabulary($id_map['vocabularies'][(int)$vocabulary_data->id[0]->data()]), $vocabulary_data, $store, $id_map);
  module_invoke_all('xml_importer', 'product', $product, $product_data, $store, $id_map);
  module_invoke_all('xml_importer', 'store', $store, $id_map);

I can't find any implementations of this hook in either Drupal 5 nor Ubercart 1. How this has ever worked in UC1 is beyond me. If any body can point out what I am missing it would be much appreciated.

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
I am now able to import products in UC 2 / Drupal 6

After a few days of hard work, I am finally able to make a product import to my UC 2 site, using the uc_importer from UC 1 as a starting point.

I have had to change quite a lot to make it work, and I am aware of several issues, that I haven't given much attention because they concern modules that I am not using (e.g. uc_manufacturer and uc_attribute).

Export is not working yet, but I will give it a go, to get an idea of what is takes to upgrade it.

That said, I can now import vocabularies, catalogs, product classes and products from xml.
If any one is interested, I can upload a 'use-at-own-risk-and-please-please-test-carefully-before-use' version.

EDIT:
Fortunately exporting turned out to be much easier than import, so I have a working module for that now too.

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Re: I am now able to import products in UC 2 / Drupal 6

I have been asked to share my module, so here it goes. Be careful though, as stated earlier, I know for a fact that some of the functionality will not work with drupal 6.x (e.g. still uses db_num_rows and such)

AttachmentSize
use_at_own_risk.tar.gz 13.62 KB
JackThompson's picture
Offline
Joined: 02/28/2009
Juice: 110
Re: Re: I am now able to import products in UC 2 / Drupal 6

I need up bulk import digital goods into ubercart..but I am getting no replies in this forum. Please someone get back to me. I feel as if I am either being ignored or there truly is no activity on this forum.

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Re: Re: Re: I am now able to import products in UC 2 / Drupal 6

As I understand it, you real problem is that your products are file downloads (right?) and so you need to associate the products you import with the actual downloadable files.

I can't say that I have tried that before, but I guess you should be able to add that kind of functionality to the importer. I would take a close look at what the 'File Downloads' module does, maybe even make calls to that module from the importer.

mogop's picture
Offline
Joined: 09/07/2010
Juice: 34
UC 2x

Hi all, this thread looks old and for Ubercart 1x so I'm curious if is there a module that fetch XML from URL and convert it (that one below looks like from cs-cart) to the UC 2x correct XML structure (and changing the encoding at the same time) so It could be imported to Ubercart 2x and create, update or delete products?

<?xml version="1.0" encoding="windows-1251"?>
<Products>

<Product>
<Main_Category_id> </Main_Category_id>
<Main_Category_Name> </Main_Category_Name>
<Sub_Category_1_id> </Sub_Category_1_id>
<Sub_Category_1_Name> </Sub_Category_1_Name>
<Product_id> </Product_id>
<Product_Model> </Product_Model>
<Product_Name> </Product_Name>
+
<Product_Description> </Product_Description>
<Product_Price> </Product_Price>
<Product_Price_Special> </Product_Price_Special>
<Product_Currency> </Product_Currency>
<Product_Vat_Rate> </Product_Vat_Rate>
<Product_Image> </Product_Image>
<Product_Image_Url> </Product_Image_Url>
<Product_Quantity> </Product_Quantity>
<Product_Weight> </Product_Weight>
<Product_Status> </Product_Status>
<Product_Manufacturer> </Product_Manufacturer>
<Product_Last_Modified> </Product_Last_Modified>
<Product_Date_Available/>
</Product>

If NO , please could you give me some directions how to do this in more automated way by myself.
Thanks

deepthi's picture
Offline
Joined: 06/27/2011
Juice: 3
Re: XML Import

hi i am workiing on drupal 6. And i need a module which can browse and xml file and then store the datat in My Sql database.
Could any one help ?

Thanks

harimohan's picture
Offline
Joined: 11/18/2011
Juice: 9
Dear Francois, Do you have

Dear Francois,

Do you have any idea to export / import stock levels and sku s in UC ??

Regrads