Import/Export

Posts: 57
Joined: 08/08/2007

I'm trying to migrate products from a shop that uses a MS Access db to UC. I first converted the data to MySQL and am now building the XML file for import. Is it right that uc_importer.module currently does import CCK image fields but doesn't export them?

I found a typo on line 212 in uc_importer.module:
$xml .= _uc_importer_export_manufacturers($dataa['manufacturers']);
should be:
$xml .= _uc_importer_export_manufacturers($data['manufacturers']);

Also, the return was commented out at the end of the function, so it didn't write any file:
return file_save_data($xml, file_directory_path() .'/uc_export.xml', FILE_EXISTS_REPLACE);

Glad ubercart.org is back(ed up?...)

Posts: 219
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

I'm keen to see a CSV import module happening (or write one myself). I was thnking that perhaps going from

Excel -> CSV -> XML -> Ubercart

would be the way forward since the XML importer already exists. Is there a spec for the XML that Ubcercart likes?

Now that I'm thinking about it perhaps Excel could export to XML and then a general XSLT template could be developed to et this in the UC preferred format?

--

suffering from too much information

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

There is a schema definition available at http://www.ubercart.org/files/store.xsd, so if anything's an approved version, that would be it. It's been changing with the importer module as I figure out the best ways to do things, but it should be fairly stable now.

Guest (not verified)

+1 for CSV -> Store

Posts: 57
Joined: 08/08/2007

I have added some custom fields (year, condition, accessories etc) to my product content type. I don't quite understand if such fields can be populated using the current importer module. Can you give me an example "snippet" that shows how data for such fields would be represented in the XML?

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

So far I've come up with something like the attached file. I didn't put any information about the kind of field because I think it's the user's responsibility to make sure the content fields are set up right on both sites. The <value> tags may be named something different for different fields, especially if they store more than one piece of information per field.

AttachmentSize
cck_fields_export.xml1.15 KB
Posts: 20
Joined: 08/15/2007
Bug Finder

Thanks Lyle. Now how would I import your xml file into Ubercart - just fire up importexportapi in Drupal and point it to the xml file?

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

When you have the uc_importer module enabled, there's a form in admin/store/products/import that you can go to that's specifically designed for Übercart files. My importer is independent of importexportapi mostly because it threw a bunch of errors at me whenever I looked at it's pages. So I started from scratch and made a custom solution.

Edit: Actually, the URL might be different depending on your version. I can't remember when I changed it, but you might need to go to admin/store/import instead. It's a normal menu item, so you should see it in the menu links wherever it is.

Posts: 20
Joined: 08/15/2007
Bug Finder

Ok thanks - that makes sense. Where can I get my hands on the uc_importer module? It doesn't seem to be on this site (at least, a site search comes up blank) and google only has one reference to it - at bazaar.ubercart.org - but it's not in cvs on drupal.org - could you please post it here as an attachment or let me know where I can download it?

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

Ah! Sorry about that. I keep forgetting what's been done since the last release, so I figured since it's in the bazaar repository you had access to it.

Here it is.

AttachmentSize
uc_importer.tar.gz9.6 KB
Posts: 20
Joined: 08/15/2007
Bug Finder

Thanks for the super-fast replies! I don't know how to access the bazaar repository, so some guidelines somewhere would be quite helpful at some point. But for now I'm going to start playing with the module and see if I can start importing products Eye-wink

Posts: 20
Joined: 08/15/2007
Bug Finder

Ok, this looks great. Easy to use too. I've got over 100 products in csv which I'll now format into the correct xml definitions - the only question is the unique_hash key. I see it's a field in the uc_products table - do I need to generate a similar (unique) hash per product in my xml importing - or can I leave it blank? I take it that it's there for some reason to uniquely identify a product?

Posts: 20
Joined: 08/15/2007
Bug Finder

Don't worry - I just found that you generate the hash in the import code.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

Yeah, the unique hash is preparation for a module that's to be used for multi-site setups. It would allow you to make a change to a product on one site, and then export that product to the other sites automatically. Because the node ids can be different, Übercart generates the unique_hash when the node is first created, allowing the module to find the right product to change.

Posts: 116
Joined: 08/08/2007
Brain Stormer

I'm a little confused. Why the third abstraction from csv -> XML -> uc and not just csv -> uc?

I imagine it's to potentially make future imports of other "types" easier (write to one interface) but it kind of creates just as much work doesn't it (at least for the person that's going to have to import the data and covert each set of data (csv etc) to the uc xml spec == 2 conversions instead of one)?

i'm biased towards csv because that's what i'm going to use to import (Eye-wink) and outside of it, i'm not sure how many different import methods actually are used in practice? If there aren't many other methods, that extra abstraction to xml might be wasted? csv is supported by php so it's a straight shot if someone builds out csv -> uc importer. And i could see people using it a lot and fairly easily. But maybe not

xml is valid i'm sure, i just haven't gone down the path yet so wondering why all the emphasis is being placed on it or what benefits it brings by using it? Maybe your importer magically insulates the coding of the actual cck fields and such that would have to be changed for every individual use of an import script.

if i had a second to breathe, i'd have finished an uc csv import script (not a module) by now but unfortunately i don't. Sad.

imho, a standardized and documented import is THE thing that uc needs right now above all else. Otherwise store conversions can't take place. That means "most" uc implementations are "probably" going to be brand new store implementations or ideas. Or that others have written their own private import scripts to complete their stores.

thanks

Posts: 116
Joined: 08/08/2007
Brain Stormer


I'll now format into the correct xml definitions

How does one take a csv file and format it into *xml* definitions? What *are* the xml definitions? Is there documentation on the uc site or is this info specified in the zip file? I guess i'm wondering what the xml definition actually means.

And can this formatting be done quickly and easily with find and replace in the spreadsheet app or vi or some other editor, or is it mostly a manual op for each record?

thanks

Posts: 20
Joined: 08/15/2007
Bug Finder

The xml field definitions are here: http://www.ubercart.org/files/cck_fields_export.xml

Or you can install the uc_importer.module and do a single product export, then take a look at the generated xml file. The xml is pretty self-explanatory.

I'm going to be writing something today which will convert my csv product file into xml. It'll be a bit of (standalone, for now) php code which will take csv as input (initially by pasting into a textarea), do the formatting stuff and then give xml as output (either in pre tags or in a textarea again). I've defined some extra CCK fields within my product type so my solution won't suit everyone. Step 2 would be to map csv fields to CCK fields dynamically - I guess since this is something a lot of people want right now there'd be a bit of demand for it?

Lyle, shall I go ahead and upload this as a contrib module once it's done? It won't be anywhere near mature - but the version I'll upload should help prepare a csv file for import into the vanilla product definition.

As for your other question, druru, why not import the csv directly into the database? Good question! I haven't looked at the uc_import module much yet, but that's the code that Lyle has written and I'm happy to work within it. If you want to go ahead and write your own csv importer, go for it Smiling Just make sure you generate the hash key in the correct way (line 762 in uc_importer.module)...

Posts: 20
Joined: 08/15/2007
Bug Finder

I'm using the converter at http://www.bytemycode.com/snippets/snippet/448/ to convert my .csv into xml. I'm about 1/2 way through so far - got the php script to read in values from the xml file. Now I'm mapping those values across to the Ubercart product field values - and adding in capacity for CCK fields.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

druru, I went with XML mostly because I was familiar with it. (I really wanted to use YAML, but PHP doesn't have an easy library for it, and everybody said no one would know what to do with it.) While CSV is technically simpler, I wasn't sure I would be able to represent things like attributes and categories easily because you don't know how many each product is going to have. I'm sure there's a technique that most people know, but I didn't, and I didn't try to find out what it was.

I would say that the two conversion steps is only useful if you already have a way to generate a CSV file of your store. If it has all of the compatible data, I think it would be easier to make XML from that than trudging through the database again.

I agree that the importer needs to be documented. I think it's as abstract as it can get because I'm using functions like node_save() and drupal_execute() whenever the data is retrieved from the XML file. I don't think I (personally) will write any other import methods, but I think anyone who wants to can emulate what's already been done.

Posts: 57
Joined: 08/08/2007

Thanks, Lyle. I've added the 'fields' element to my XML, updated uc_importer.module to the latest revision and import works smoothly to my custom fields. But how about images? Image import is commented out around line 815 in uc_importer_import()...

Posts: 20
Joined: 08/15/2007
Bug Finder

futurist, you're working directly on XML right - you're not generating it from csv? Otherwise I'd love to have some of that code! Eye-wink

Posts: 57
Joined: 08/08/2007

I'm migrating products from an old shop into UC. Like I said in my first post, I go Access -> MySQL -> XML -> UC. I've written up a custom PHP script to generate the XML according to Lyle's example (cck_fields_export.xml). It's similar to the export.php he published with the first release of uc_importer.module (see this archived thread). I'll try documenting my script once I get image import to work Eye-wink

Posts: 20
Joined: 08/15/2007
Bug Finder

Ok thanks - can't find a copy of export.php but I'm guessing that's incorporated right into the uc_importer module now. Reading through that link you just posted it seems that the importer only works with php 5...doh! My testing and production server are both running 4...although I have a spare Mac which I could install 5 on.

Posts: 57
Joined: 08/08/2007

No, export.php generates the XML uc_importer likes from an existing MySQL db. Since the shop you are migrating from can have any structure, this must be custom code. I'm also using my export.php to map old relations to the custom fields in my UC product type.

Posts: 57
Joined: 08/08/2007

Another problem: All imported products are 'orphaned' even though I've assigned a term id to each of them like so:

<product>
  <type>product</type>
  ...
  <categories>
    <category>
      <id>11</id>
    </category>
  </categories>
</product>

The terms were created before the import in admin/content/taxonomy. The tid '11' corresponds to one of those terms. What's wrong? (There is no insert to the term_node table in uc_importer...)

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

The original importer module only works with PHP5 because of Simple XML. Because I found JSimpleXML from Joomla! which works in PHP4, I've rewritten the importer to use it in case anyone's still stuck in PHP4.

Edit: Removed due to errors. See below for an updated module.

Posts: 57
Joined: 08/08/2007

Hmm, any idea concerning my image import and category issues? Thank you.

Nevmoor (not verified)

I have just found this great set of modules and it looks like it will do everything I need BUT I am a n00b at drupal and know very little programming. I have read this thread and have created a CSV file from Excel of a list of products for a NEW store. I don't quite understand the steps needed to convert to XML>IMPORT to UC. Could you tell me how to use the script mentioned earlier in the thread? I have downloaded the TXT file but how do you execute the script??

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

Spent this afternoon typing this out: http://www.ubercart.org/docs/user/354/importing_data

The part your looking for is "/store/products/product/fields" and right after. Hope it's helpful.

Posts: 20
Joined: 08/15/2007
Bug Finder

Hi Nevmoor - I'm working on a csv -> XML script as we speak. Once your data is in XML it's pretty simple to import it into Ubercart using the instructions earlier on this page. Might be an idea to export some of your products into XML using uc_importer.module and then import them back so that you start to get a feel for how the whole process works. I'll post my script on this page once I'm done Smiling

Posts: 20
Joined: 08/15/2007
Bug Finder

Thanks Lyle, the php4 version of the importer looks good. Just had 2 errors when I ran it - and they were silly fixes:

Line 744 I changed to:

        $fix = $product_data->unique_hash[0]->data();
        watchdog('importer', '<pre>'. print_r($fix, true) .'</pre>');
        if (!isset($fix)) {

Line 853 I changed to:

          $fix = $attribute_data->default_option[0]->data();
          $default_option = isset($fix) ? (string)$attribute_data->default_option[0]->data() : $attribute_data->options->option[0]->id[0]->data();

In both cases this has to do with php4 seemingly unable to process the following code within a larger

$product_data->unique_hash[0]->data()

But now that that's done, I installed the php4 module (by overwriting the other one in the uc_module folder) and it's not picking it up as a menu item in the store backend like it did with the latest version. Am I missing something?

Posts: 20
Joined: 08/15/2007
Bug Finder

This might be because I first used the php5 version and am only now using the php4 version. The link defined in the php4 version is "admin/store/products/export" and if I navigate there (with the module installed) it just takes me to the "admin/store/products" page. Suggestions?

Btw, in terms of progress with the csv -> xml converter (before I head to bed) is good (but slow): I've got it to generate the following code from my csv:

<products>
<product>
<type>product</type>
<name>Aciphex (Pariet)</name>
<manufacturer>Janssen-Ortho</manufacturer>
<cost>$49.10</cost>
<fields>
<field>
<name>field_generic_name</name>
<delta>
<value>Rabeprazole Sodium</value>
</delta>
</field>
<field>
<name>field_strength</name>
<delta>
<value>10mg</value>
</delta>
</field>
<field>
<name>field_type</name>
<delta>
<value>International Brand</value>
</delta>
</field>
<field>
<name>field_sabre_name</name>
<delta>
<value>Pariet 10mg Tabs (Janssen-Cilag)</value>
</delta>
</field>
<field>
<name>field_pack</name>
<delta>
<value>28</value>
</delta>
</field>
</fields>
</product>
</products>

I haven't yet enclosed it within a store tag and the catalog category. I've also got a CCK field which references a category within drupal and I'm not quite sure how to link that across (by term id? Does the importer support categories?)

ps - I'm doing this for a client, so NO I'm not selling pharmaceuticals and YES I'm making sure he isn't sending out ANY emails.

Posts: 57
Joined: 08/08/2007

Your new documentation is a great help. However, I'm still confused concerning image import. The XPath /store/products/product/image appears in the schema definition but not in the documentation. So I dropped the 'image' element from my product and instead tried the following (assuming that image type fields should now appear similarly to text type fields in the XML):

<fields>
  <field>
    <name>field_image_cache</name>
    <delta>
      <value>http://mysite/import/example.jpg</value>
    </delta>
  </field>
  ...text type fields...
</fields>

An image file 'example.jpg' exists in the 'import' dir. But that doesn't work either. Can you please tell us if image import works at all with the module and if yes, give a short example on how the XML should look?

@macgeek: Sometimes I noticed that disabling and then re-enabling a module made it appear in admin.

Posts: 20
Joined: 08/15/2007
Bug Finder

Ah, newbie error. That did the trick, thanks Smiling

Nevmoor (not verified)

This is great! I am slowly 'getting it'. I need to do the importer for PHP4 so I am going to use the above advice for changing the code to get it to work. If I can get this down, I will be able to do 3 or 4 online stores in the next couple of months!! I will definitely keep up with these forums.
BTW does anyone have a suggestion for a PHP editor? I have DW but that doesnt cut it for me.
I am doing all these changes to a subfolder of an active site on shared hosting,which I know is a little dangerous but since it's not really up I hope I don't crash anything!

Posts: 24
Joined: 08/17/2007

OK I am starting to 'get it'. I have been playing around with this a bit. Now I need to make the.module change for the PHP importer so I can try to export an example product. macgeek, whenever you get you script done let me know! I am no programmer at all, but I can manipulate code once I understand a little of how it all works. Keep up the good work everybody!! UC is a great module for drupal

Posts: 4
Joined: 08/08/2007

Thanks, Lyle! Cheers all around! Now, about that YAML... Smiling

Posts: 24
Joined: 08/17/2007

Just found out my client actually had a MS Access database as the original form of their product list! Access has an export to XML function. SO... I wanted to test this out.

I tried to export a product from UC and then re-import it.
all I got in the exported file was this:

<?xml version="1.0"?>
<store xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ubercart.org http://www.ubercart.org/files/store.xsd"></store>

What am I missing? I have taken the Access database and added/shifted the column orders to match the schema you guys linked to. I just want to get the import/export module working as step 1.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

You have to press the "Select" button to get products in the bottom box before the exporter will pick them up. It's a bit convoluted, but it allows you to get products from more than one category at once. While the exporter works, it does need some polish and documentation still.

Posts: 24
Joined: 08/17/2007

Actually I discovered a few things that were basically theme issues. To bad Drupal doesn't have a lot of folks doing cool themes. It's getting there but for us lazy folks it's difficult. I am going to stick with the default until the store is functional. Then I will reach out for help!!
I just exported my test product and everything lines up. Now I have to get the importer to work. My host has PHP4.3.11!! When I FTP the importer.module ( the renamed importer_php.module) into the importer module folder, I get a Drupal crash and the whole site locks up. I am probably doing something stupid, but it's just my code ignorance. I will try again this evening and let you guys know whats what.
THANKS!

Posts: 24
Joined: 08/17/2007

Getting this error again

Fatal error: Call to undefined function: simplexml_load_string() in /home/content/F/o/r/mysite/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 656

I know this has to do with the importer for php4 vs 5 simple xml but I don't know how to solve it.
Are all the code fixes mentioned in the above posts already coded into the latest uc_importer?

I also just got an error from the pathauto module:

warning: preg_match(): Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 3 in /home/content/F/o/r/mysite/html/store/sites/all/modules/pathauto-5.x-2.0-beta2/pathauto/pathauto.inc on line 72.
Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

Ah, I had nearly forgotten the code fixes. Here's the corrected file.

When you get it, you'll need to rename it to uc_importer.module and replace the module file you already have. Then, you should disable and re-enable it to make sure Drupal loads the correct thing. You were getting an error because it was still using the 5-only version.

Also, pathauto seems to be kind of broken. We'll forgive them because it's still in beta, but you might want to stick with previous versions until it gets sorted out.

AttachmentSize
uc_importer_php4.zip8.33 KB
Posts: 57
Joined: 08/08/2007

No more orphaned products after import! I had set up product categories in admin, added some products manually and then tried to import more using uc_importer. But the imported products didn't have any category assigned to them. Here is how it works (thanks, Lyle):

Since you know ahead of time which products go in which category, you should "import" those categories too. Since they'll have the same name in the XML and the database, the importer will recognize the duplicate and decide what to do based on its configuration. Since the default is "do nothing", it will map the to the term id and be able to put the products in the right place when it gets to them. Considering that you already have the products with the right term id, you can give the tags the same number. It's only used as a reference.

(I think this should go in the documentation.)

The only missing thing now is image import...

Posts: 24
Joined: 08/17/2007

Lyle, I just dropped the importer module for PHP 4 in to the uc_importer folder( after renaming it of course) and I got another error:

Parse error: parse error, unexpected '(', expecting ',' or ')' in /home/content/F/o/r/myinfo/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 746

Is there anything I should be changing in the code that I don't know about?

BTW what is a good open source app to view/edit code?
Dreamweaver is a pain sometimes when you try to go line by line. It doesnt always show things on the 'right' line number consistently.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

I bet that's the same kind of error that macgeek caught earlier. Change that line to

<?php
       
if (!isset($product_data->unique_hash)){
?>

and that should take care of it. There's a few more lines that will do the same thing because of the isset(), so either change your copy or get the updated one in the post above.

Boo on Dreamweaver. We use jEdit, and I haven't found another text editor I like better.

Posts: 24
Joined: 08/17/2007

The site I am doing is hosted by godaddy( my clients choice not mine)
I found out that they actually have PHP 5 installed but you need to make the file extension .php5 in order for the script to be run in 5. I think thats stupid, isnt 5 mostly back compatible? Wouldn't it run all .php scripting or is there something I don't know??
SO....Does this mean I only have to change the extensions in the uc_importer module code? I would hope so.
I am going to try that while I wait for your replies. I know you guys are busy working on your own issues so that's thanks for dealing with a n00b!!!.

Posts: 332
Joined: 08/07/2007
Administrator

Nevmoor,

If you're using Linux hosting for GoDaddy, setting the following lines in your .htaccess file will make the server use PHP 5 as the default with files using the .php extension:

AddHandler x-httpd-php5 .php
AddHandler x-httpd-php .php4

If you're using Windows hosting...well I don't know.

--

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

You wouldn't want to change any of the module files because they don't have php extensions. Instead you'd change the files that actually run Drupal, like index.php and update.php. I believe those are the only two files that are called directly by the browser. Everything else gets loaded by include(), so they should be run by PHP5 as well.

To avoid any unexpected "File not found" errors, I'd see if you can get godaddy to go in the other direction, and make PHP 4 have the special extension. I think they can do that on a directory by directory basis, so that shouldn't affect anyone else hosted on your server.
It seems Shawn beat me to it. Sticking out tongue

Posts: 38
Joined: 08/16/2007

I've got a nice excel sheet with all the info.
Trying to map it to the store.xsd. Quite a job, maybe Access is easier?

If I ever succeed I'd like to help with an extension to SimpleStock import.
What's the current development status of that?

It would seem logical to expand the XML Schema Description with SimpleStock values?
something like
/store/products/product/simplestock,Container, No unbounded
/store/products/product/simplestock/numberstock, Decimal, No 1
/store/products/product/simplestock/trackproduct, Integer, No 1
/store/products/product/attributes/attribute/options/option/simplestock, Container, No unbounded
/store/products/product/attributes/attribute/options/option/simplestock/numberstock, Decimal, No 1
/store/products/product/attributes/attribute/options/option/simplestock/trackproduct, Integer, No 1

Or are there other stock import ideas?

Posts: 332
Joined: 08/07/2007
Administrator

I win again! Woo hoo!

--

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Posts: 24
Joined: 08/17/2007

I found that .htaccess thing last night but I am just about to get into it and change it. I will let you guys know what happens after all the changes. UBERCART RULEZ!

Posts: 24
Joined: 08/17/2007

I am now running PHP 5.1.4 !!!!

I was also seeing if I could get my MS access database straight to XML without doing the MS Access>mySQL step. the XML isn't exact, but with a little manipulation I think it will eventually work.

Posts: 20
Joined: 08/15/2007
Bug Finder

Hi Lyle

I've upgraded to php5 and am using the php5 version of uc_importer (dated August 9th - don't know if you've done updates on it since then?). Using that, if I export a single product and then use the resultant xml file to try to input, it gives me a failure:

    * warning: Invalid argument supplied for foreach() in /Users/roger/Sites/bestbuydrugs.net/website/ubercart/drupal-5.2/sites/all/modules/uc_importer/uc_importer.module on line 676.
    * warning: Invalid argument supplied for foreach() in /Users/roger/Sites/bestbuydrugs.net/website/ubercart/drupal-5.2/sites/all/modules/uc_importer/uc_importer.module on line 697.
    * warning: Invalid argument supplied for foreach() in /Users/roger/Sites/bestbuydrugs.net/website/ubercart/drupal-5.2/sites/all/modules/uc_importer/uc_importer.module on line 738.
    * warning: Invalid argument supplied for foreach() in /Users/roger/Sites/bestbuydrugs.net/website/ubercart/drupal-5.2/sites/all/modules/uc_importer/uc_importer.module on line 844.

These lines have to do with categories (I also have a few custom CCK fields - see my xml posted earlier on this page) - should my import be failing, or am I doing something wrong?

Posts: 24
Joined: 08/17/2007

I got these errors tonight

# warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 656.
# warning: Invalid argument supplied for foreach() in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 658.
# warning: Invalid argument supplied for foreach() in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 670.
# warning: Invalid argument supplied for foreach() in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 676.
# warning: Invalid argument supplied for foreach() in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 697.
# warning: Invalid argument supplied for foreach() in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 738.
# warning: Invalid argument supplied for foreach() in /home/content/F/o/r/ForDivinity/html/store/sites/all/modules/uc_importer/uc_importer/uc_importer.module on line 758.

I got back to the original uc_importer for PHP5. I thought I had the schema right but I guess not.

Posts: 24
Joined: 08/17/2007

OK I did some quick work on my XML.
now the importer says it was successful but there are no new products added!!
I suspect that my XML must not be right. I have almost 400 products so I have to get this to work. Actually I probably could have done this by hand after all this time but I want to get this right!

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

bkudria had been having the same kind of problem on Friday, but we couldn't figure out the problem. I was able to take his XML and import it with no problems.

nevmoor, it sounds like you have a different problem, though. Post your XML so I can see if there's anything to change.

Posts: 38
Joined: 08/16/2007

To use SimpleStock, every option should have it's own SKU (model).
But the import has no way to import a "model" to a product-option.
Is that on the todo list already?

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

It wasn't, but I guess it can be. Shouldn't be a problem to get that working.

Posts: 20
Joined: 08/15/2007
Bug Finder

Ok, well that leaves me kinda stuck! I can generate similar xml but can't import it. So I offer up my csv->xml converter script, which gets me to the same point of the uc_importer generated xml after a good product export.

First, export your excel document into csv, with the first row being column headings. Then fire up the csv2xml.php script in your web browser, and make sure you've uploaded your csv file into the same path.

I've also attached the example file I've used as my csv input (just 2 rows - a header row and a product data row) - just remove the .html at the end (comments don't allow a .csv file as an upload option).

It's rough and ugly, but does the job. Let me know if it's useful. Ideally it would be integrated into the uc_importer module. And optimised! Right now it reads the .csv file about 3 times during the course of the export...

AttachmentSize
product-single.csv_.html229 bytes
csv2xml.php_.txt12.52 KB
Posts: 38
Joined: 08/16/2007

If i run the import twice, all the manufacturers,the attributes, the categories are overwritten (that was my option in the configuration), but the products are not.
It looks like the import needs the same "unique_hash" to be overwritten.
That does make sense, but wouldn't it also make sense that the SKU is used as an identifier for a product to be overwritten? Maybe as option in the config?

Posts: 38
Joined: 08/16/2007

aaah,

function uc_product_insert($node) always creates a new unique_hash.
So you cannot use the hash across systems right now.

I think I will get this bazaar thing working. I need the latest code.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

I've committed a change to the importer (both versions) to handle product model adjustments. Attributes and options can now import and export their ordering and price and weight defaults. I've also fixed some problems in the PHP4 version that might have been causing problems for some of you.

I think there might still be issues with assigning options to products, especially if there are already existing options with the same name. I haven't isolated the problem yet, but it's something to be aware of.

Posts: 57
Joined: 08/08/2007

There is an "undocumented" feature in the importer module: Image import Eye-wink

(Something like) this should be added to the schema description:

/store/products/product/image (Container; No, unbounded; Container for the image data.)
/store/products/product/image/path (String; Yes, 1; Path to the source file.)
/store/products/product/image/title (String; No, 1; Image title.)
/store/products/product/image/alt (String; No, 1; Image alternate text.)

Perhaps the documentation should also remind us that for image import to function, images must be uploaded with FTP to the source directory specified in the path element prior to running the importer.

I'm not sure how it is defined in Drupal (or Image cache?) which image file types are supported and if there is a limitation to the size of the source files. Maybe a reference to these could be made in the documentation too.

Finally, what kind of surprises me is that apparently no addition (path, title, alt) was necessary to the schema.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

I didn't put the image in the documentation because I thought I would be taking it out. As it happens, I'm leaving it in.

I think each site can have different settings for its Imagefield, so the importer should conform to whatever settings those are in terms of file type and size. There isn't a hard limit on the size of the files, but you should know that the files are transferred from the source directory to drupal_root/files/ubercart_images on your site.

I'll detail all of this in the documentation today.

Posts: 57
Joined: 08/08/2007

Thanks. I wouldn't mind if you took out the image and used field/type, field/name and delta for path, title, alt instead. Or anything you prefer - as long as the importer supports image import.

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

That's what I wanted to do, but it doesn't work so well because image fields are really references to the file rather than the actual image data. Either the images would have to already exist on the new server and in the files table, or there would be a lot of broken links. That doesn't work, so we're back to handling images as a special case.

Posts: 116
Joined: 08/08/2007
Brain Stormer

hate to be a wanker.. but since this is a pretty huge thread and a mighty useful one, does any of the participants in this thread that have actually walked through this process feel like documenting an actual import case with a mock set of data. i know it would save me a lot of time as well as many others in the near future. so it's going to be a total volunteer effort by whoever does it if they decide to.

posters here are using real data in real life backend situations that we in the forum's don't see. lyle understand's the questions they ask because he designed the import module. that leaves me and maybe other's trying to visualize what they're "really" talking about. how to get from A (my data) to Z (imported and mapped correctly in a working uc).

It doesn't have to be a thesis. But a numbered list of steps that maps a sample product record with images would be fantabulous. An occasional "gotcha" or "be careful" note would seal the deal.

thanks for any takers on this one.

Posts: 24
Joined: 08/17/2007

macgeek, lyle.....
I used the CSV to XML script. WORKS GREAT! It does exactly what it should. BUT.....
Even though everything looks good, uc_importer still doesn't actually create the products or at lease UC doesn't seem to see them...
The XML file: oil_list1.xml

Posts: 38
Joined: 08/16/2007

oil_list1.xml is not a proper XML file
All "&" signs should be "&amp;"

good luck

Posts: 57
Joined: 08/08/2007

@druru: I do understand your wish. I myself sometimes find the API or other documentation (Drupal in general, not just UC) very concise and clean - but lacking examples. I'll try and write up a summary of "my" A-Z (as of the first post in this thread) with some data snippets shortly.

@Ryan/Lyle: Where should such a "tutorial" be posted? In contributions? Will you eventually move approved tutorials to the "Importing Data" handbook?

Posts: 6997
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Docs/tutorials would be great and may be posted as children pages in the handbooks wherever it seems appropriate. If you can't find a good spot, post it in the closest one and send me a PM. I'll try to create a guides/tutorials section here in the next few minutes.

EDIT: Use this for now - http://www.ubercart.org/docs/user/561/tutorials

Posts: 24
Joined: 08/17/2007

catorhans:
I didn't realize there were any in the product names. It is a large database. I am doing a search and replace and will try it again!

Posts: 116
Joined: 08/08/2007
Brain Stormer

very good futurist, regarding documenting an import example. I'll look forward to it.

thought. i just created a child page in the user guide for paypal wps and installed it in the 'payments' section of the guide. that way when someone goes to find out about the payment options for paypal, the configuration example is right there in context. no jumping to a separate section of the site to try to find a related post.

not sure if ryan wants you to put your documentation page in the tutorial section but it would seem better to me to include it where the import is mentioned in the user guide. again, it allows an uc user to go to one spot, find out about the import/export modules and see a related example.

my 2 cents

Posts: 57
Joined: 08/08/2007

@Ryan: Thanks for providing the tutorials section - and the pager for monster-threads like this.

@druru: Thanks for your PP WPS tutorial. Will use that later to tune my setup... Btw.: WPS should be Website Payments Standard as they call it over at PP Eye-wink. I agree that all documentation related to a topic should be concentrated in its child (handbook) pages, like on drupal.org. Will post my doc asap (within a few days).

Posts: 116
Joined: 08/08/2007
Brain Stormer

Nice.

I actually might be able to use it in a couple of days Smiling. And depending on my experiences, i can add to the page as well.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

I'm trying to import an xml file I've managed to generate from an osCommerce database and I get the following error:

Fatal error: Call to a member function on a non-object in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 786

Might this be due to my version of PHP? It used to be PHP4 but my host said they were upgrading to PHP5. Not sure if it's related yet.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Oh.. hold on a minute.

I'm using my local dev server so it's PHP5. I've got the PHP4 version of the importer. I'll try that.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

I've just updated to the bazaar version and changed the module to the PHP4 version and I'm still getting the same error. Any ideas?

Posts: 219
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

I'm not sure about which error your pulling exactly as I'm using the latest Bazaar version for PHP5 and I've also been hacking into it to make it work. But I'm guessing that your XML file is missing one of the core features like

/store/categories/category
/store/manufacturers/manufacturer
/store/products/product

etc which i assumes are there even if have no data for them. Perhaps disable all the modules you have no data for (including attributes). I would be interested to know if you manage to get images importing.

--

suffering from too much information

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Hi CpILL, Lyle just informed me about those fields being required. I left them out of the XML since I didn't need them at this time. Also, the /store/products/product/weight_unit is required but not exported in my test export. I will add them all to my script and see how it fairs.

Will make sure I let you know if I manage to import images.

Posts: 219
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

cheers mate

--

suffering from too much information

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

CpILL, I actually managed to get images imported quite easily from custom generated XML. This is what I have in my XML:

<image>
  <path>/var/www/html/import/trd_carbon_emblem.jpg</path>
  <alt>TRD Carbon Emblem</alt>
  <title>TRD Carbon Emblem</title>
</image>

I created a directory in my web root (html) called import for all the product images and made sure I had permissions set to 755. I'm also running the bazaar code from about 4 hours ago.

Hope this helps.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Actually, that's a complete lie. It's copied the image file but the file is empty i.e. 0 bytes. The imagecache preset is being shown because I didn't delete it before testing. Sorry to get your hopes up. Will keep trying.

Update: I tried again and it worked just fine. Getting a few foreach errors so will add whatever missing tags are causing them (hope this is the issue and not something else).

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

I've managed to get everything sorted on my end and have just posted a short run through of what I did.

Posts: 219
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

Also, I should mention that now you can associate products with any existing taxonomy term

/products/product/vocabularies/taxonomy@id="X"/term = Term name

i.e.

<products>
  <product>
    <vocabularies>
      <taxonomy id="6">
        <term>Create Yourself</term>
      </taxonomy>
      <taxonomy id="5">
        <term>Alexandre Herchcovitch</term>
      </taxonomy>
    </vocabularies>
...

but you'll need a recent verion of importer form Bazaar

--

suffering from too much information

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

Some of the improvements I made to the importer was support for different vocabularies. I put the definitions for them above the <categories> tag, and each category now has a <vid> tag. As mentioned elsewhere, documentation is still pending. Documentation is up to date.

I also wanted to mention that the importer is completely compatible with PHP4, now. There isn't any more silly file switching to get the right version.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Hi Lyle, thanks so much for this and all your continued efforts. Will check it out.

Posts: 10
Joined: 01/02/2008

Hi -

Great module and very useful thread. I was able to pull together the XML format pretty quickly. I came across the parsing error too and realized from inspecting the module code that id and unique_hash appeared to be required. Since I was importing fresh, I added the tags and left them empty.

The result is that only the first product actually makes it into the import. I also tried assigning explicit IDs to the individual product nodes, but that had the same effect.

I'm attaching a short sample of my generated XML file.

Any help/suggestions would be much appreciated.

Thanks

Faisal

AttachmentSize
__exportXML.php_.xml4.62 KB
Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

The products ought to have explicit, unique ids. I don't think I want the unique hash to be required, but I've forgotten what the latest code is doing. If you use md5() on all the elements in the <product> tag, that should be sufficiently unique to use as the unique hash.

Posts: 10
Joined: 01/02/2008

Lyle -

Wow - that was quick! Since the last activity on this thread was from a while ago, I wasn't expecting a response soon.

That worked perfectly. Once I assigned a unique hash, the import worked as expected - thanks!

Posts: 21
Joined: 12/12/2007
Bug Finder

And note that you'll want your unique hash to be consistent across re-imports, if you want to overwrite existing products (as I usually do, because our catalog is maintained in excel and then continually re-imported into ubercart via the importer).

Posts: 9
Joined: 01/05/2008

Hi, trying to export data in XML, in order to understand the structure of the file. But I get the following:

Notice: Undefined offset: 4096 in D:\usr\www\ittrend\includes\common.inc on line 553
Notice: Undefined offset: 4096 in D:\usr\www\ittrend\includes\common.inc on line 560
...
Bla-bla-bla

After I added these lines in .htaccess

php_value error_reporting 7
php_flag display_errors off

...I received a temp-file-uc_export.xml (Hmmm... why "temp-"?Smiling)
and I think I find error the reason: non-latin characters are not supported by XML-generator Sad

    <vocabulary>
      <id>9</id>
      <name>Вендор</name>
      <description></description>
....
    </vocabulary>
    <vocabulary>
      <id>10</id>
      <name>Вид</name>
      <description></description>
....
    <category>
      <id>159</id>
      <vid>10</vid>
      <name>&ETH;œ&ETH;&deg;&Ntilde;€&Ntilde;.....name>
      <description></description>

I guess is intergalaxian aliens' language Smiling In my example Вендор actually is "Вендор" (Russian), Вид is "Вид". It's very fun and buggy. Please help. Smiling

--

Nosce te ipsum

Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

Those are just Notices, and Drupal 5 does a lot of things with PHP that causes them. Fortunately, Drupal 6 fixes all that. What you should probably do is change the error reporting in php.ini to E_ALL ^ E_NOTICE. Notices aren't dangerous and can be ignored for the most part.

The other problem you're having is some conflict in the character encoding. I'm going to guess that your database has a different collation than Drupal expects. Which is UTF-8, by the way. I don't have any explicit encoding directives in the XML output because I was trying to avoid something like this.

Posts: 57
Joined: 08/08/2007

Hi, I'm having trouble to import images with the current (Beta 7) importer module. Is it possible that <path>http://mydomain/files/ubercart_images_to_import/filename.jpg</path> doesn't work? Do I have to use the absolute path from the server root? Edit: Yes. Otherwise allow_url_fopen would have to be turned on in the PHP settings. Changed to absolute path.

Also I'm wondering if the Documentation is up to date. Apparently these tags are now required?

/store/products/product/weight
/store/products/product/weight_units

Edit: This also seems to be required now:
/store/products/product/unique_hash

Posts: 26
Joined: 03/13/2008

Hi, folks. I've just helped my first client make the switch from OsCommerce to Ubercart, and I'm pleased to say she's just made her first two sales!

Thing is, she's used to being able to pull up a spreadsheet of all orders for each product, including all of the custom fields for that product, in a spreadsheet that she can copy and paste into Excel. I'm up to the challenge, but I wonder if anyone has done this before and has any tips to share. Are Views my best bet? Is it possible to do one View that shows all the fields for all product types, or would that just be silly?

Thanks in advance! --Ben

Posts: 3
Joined: 05/17/2008

Hi all,

I'm so close to make importer_module works, I tested with 1 product and works fine BUT when I want to add the rest of products it just import the first one... I'm sure it's something like an option not activated somewhere but don't know where, does anybody can help?

Posts: 12
Joined: 06/19/2008

Hi ottavio78 ,
I've managed to import 1 product too. When I try 2 or more, it imports only the first one. If you found a solution, pls let me know

Posts: 116
Joined: 05/28/2008

try using OpenOffice to create the CSV file, there may be an issue with line endings or something.

Posts: 12
Joined: 06/19/2008

I saw something strange. It actually uploads the records, but creates one record, and then revisions of him, so only the last one remains, the others are revisions. The id tag of all are different and I export the IDs from a database.
The import actually works, but I don't know how to make him do what I want. How he desides that next "product" is a revision of previous ones?

Posts: 3
Joined: 05/17/2008

This is the XML i'm trying to import

hope will be useful for somebody to understand what i'm missing

AttachmentSize
Copia di test1.xml4.25 KB
Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

There's a number of problems with that XML I can see. You only have one vocabulary, but you're trying to put your second category into a second vocabulary. The <vid> tag should be 1 for both Teologia and Scienza. This is probably why the second product doesn't get imported because it's trying to be put into a category that failed to be imported properly. Or maybe it did get imported, and it's just hard to find.

There are several places where you have large structures in the XML tree without any data in them. You probably don't need to include them. <manufacturers> and <attributes> are the main things. And since there is a <model> tag directly on the product, you don't need to specify the one model in the <adjustments>.

Finally, it should be spelled <length_units>, not "lenght_units". The value of this tag should be cm instead of 1

Posts: 44
Joined: 01/09/2008
Bug Finder

I've just submitted a patch for uc_importer at http://www.ubercart.org/issue/6129/extend_uc_importer_export_csv that allows exporting products (nothing else yet) in CSV format. The format is compatible with that used in http://www.ubercart.org/contrib/5221 . It adds a select box on the product export page to allow choosing between xml and csv.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

I'm actually having issues importing products at the moment. Everything is working fine apart from categories. The categories themselves are importing properly but categories are not assigned to the products. I've attached my XML file in case anyone can see why this isn't working.

I checked uc_importer.module but can't find where the categories are being assigned to the products.

Any ideas?

AttachmentSize
uc_export.xml8.27 KB
Posts: 2848
Joined: 08/07/2007
AdministratoreLiTe!

For whatever reason, the categories aren't assigned to the imported product if the uc_catalog module isn't enabled. Your XML looks good to me, so that might be the issue.

Posts: 339
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Thanks so much Lyle, that's exactly what it was!

Some of the imported content is a bit malformed.

There is a category in my XML named 'Sofas & Chairs', when this is imported it becomes 'Sofas&Chairs'.

The product description is like so in the XML:

Available in 6 colour ways: Natural, Brown wash, Ivory, Sea blue, Olive and Black. The Louise chair by Lloyd Loom is a classic shape and design. There is an optional seat cushion available. Lloyd loom is enjoying a strong revival and is being incorporated into styles for dining furniture, bedrooms, kitchens and conservatories.

Lloyd Loom grew from strength to strength as their furniture became increasingly popular. It could be seen on ocean liners, in hotels and tea rooms; it became the standard issue for the British Army and RAF all over the world; it even graced the Royal Boxes at Wimbledon, Henley and Twickenham.

Using experience gained on the factory floor has proved invaluable in recreating the original shapes and manufacturing techniques. The design department concentrates on strict adherence to original designs and on an ever developing modern collection.

but ends up like this in the database:

Available in 6 colour ways: Natural, Brown wash, Ivory, Sea blue, Olive and Black. The Louise chair by Lloyd Loom is a classic shape and design. There is an optional seat cushion available. Lloyd loom is enjoying a strong revival and is being incorporated into styles for dining furniture, bedrooms, kitchens and conservatories.Lloyd Loom grew from strength to strength as their furniture became increasingly popular. It could be seen on ocean liners, in hotels and tea rooms; it became the standard issue for the British Army and RAF all over the world; it even graced the Royal Boxes at Wimbledon, Henley and Twickenham.

Using experience gained on the factory floor has proved invaluable in recreating the original shapes and manufacturing techniques. The design department concentrates on strict adherence to original designs and on an ever developing modern collection.

The custom CCK field is like so in the XML:

Double (4'6"): W 156cm x D 210cm x H 129cm
Kingsize (5'): W 171cm x D 217cm x H 129cm
Super Kingsize (6'): W 201cm x D 217cm x H 129cm

Bedding not included

and ends up like this in the database:

Double (4'6"): W 156cm x D 210cm x H 129cmKingsize (5'): W 171cm x D 217cm x H 129cmSuper Kingsize (6'): W 201cm x D 217cm x H 129cmBedding not included

Notice how the description doesn't have all newlines removed.

Any idea why this might be?