Error Importing XML

Posts: 329
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. I'm just trying to import one product as a test. I've changed the uc_import.module to the PHP4 version. This is the error I receive:

Fatal error: Call to a member function on a non-object in /modules/ubercart/uc_importer/uc_importer.module on line 792

Here is my XML file:

<?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">
  <products>
    <product>
      <type>product</type>
      <name>Fuel Filter (EP82/EP91)</name>
      <description><p>Replacement fuel filter for all Toyota Starlet models.</p></description>
      <model>TOY-FUE-0007</model>
      <list_price>0.00</list_price>
      <cost>0.00</cost>
      <sell_price>10.00</sell_price>
      <weight>0</weight>
      <image></image>
      <fields>
        <field>
          <name>field_application</name>
          <delta>
            <value>EP82 GT/EP91 Glanza/4efte/4efe</value>
          </delta>
        </field>
        <field>
          <name>field_extrainfo</name>
          <delta>
            <value>N/A</value>
          </delta>
        </field>
        <field>
          <name>field_deliveryinfo</name>
          <delta>
            <value>Free UK Mainland Delivery on all items.</value>
          </delta>
        </field>
      </fields>
    </product>
  </products>
</store>

As you can see I've left out the <unique_hash> as this is a fresh import and not a replacement of an existing product. I also left out the <id> since I want it to increment what is already there.

This is the only POST in the access log (strangely nothing in the error log):

82.1.171.97 - - [11/Oct/2007:12:17:44 +0100] "POST /shop/admin/store/products/import HTTP/1.1" 200 182 "http://www.toytuning.com/shop/admin/store/products/import" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11.1 (KHTML, like Gecko) Version/3.0.3 Safari/522.12.1"

When I return to a working page it says 'File uploaded successfully' but throws out the following error:

  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 673.
  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 685.
  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 721.
  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 768.

I have the possibility to switch to PHP5 since my host has just updated their servers to provide both. Should I ask them to switch that site over to PHP5?

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

I think I'm going to have to do a major overhaul of the importer module. There's been some changes to the product definitions that haven't been updated, and I need to make more provision for custom-generated XML. Especially since it's not really working like I've said it should.

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

Oh, by the way, that first error about member functions on non-objects is about the weight_unit field. The importer is expecting it now for some reason, but it's not in your XML.

The rest of them are because it expects the <categories>, <manufacturers>, <classes>, and <attributes> tags, even if they're empty. This is one of those things that I need to fix, and I'm not sure there's anything you can do in the mean time except import all of those pieces of data.

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

Hi Lyle, that would be great. For us (and I expect most others) the XML importer/exporter is so important so thanks for providing it.

I found it really easy to get from an osCommerce database to the XML but wasn't sure which fields are strictly required. I read in another forum post that unique_hash can be left out if it's a fresh import. What about id, is that required?

I also noticed that I left the image field empty. What should be in this field to import them properly, where should the images exist etc.?

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

Ahh, OK. Thanks for the insight. Will update my script to add those tags. I thought it might be something like this.

This seems like it will allow me to work around it just fine. Will report back.

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

Regarding weight_unit.. I have added a weight of 1 in units of kg but when I export the tag is not there.

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

And that's why it needs an overhaul to get it up to date.

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

Ahh, sorry, I get it now.

I've got about another 150 products in a text file to add, I better get on with them in the meantime. Going to try CpILL's CSV importer module too.

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

Just a little update on this matter:

I've just switched to PHP5 and the importer module now works. Everything but the images which I'm going to keep trying.

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

Now that I've sorted out my problems with PHP thanks to Ryan I've managed to get the XML importing working with images. I am using some additional CCK text fields that are displayed on the product page as part of the description and am using PHP5. Here is my process and some things to consider:

1. Export one of your products so you have some XML to work with. I used XML Tidy (built into TextMate) so I could read the exported XML.

2. I tried to import the exported XML to see if it would work but it gave me a bunch of errors:

  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 745.
  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 793.
  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 922.
  • warning: Invalid argument supplied for foreach() in /var/www/html/shop/sites/all/modules/ubercart/uc_importer/uc_importer.module on line 963.

Lyle enlightened me that I needed to add some required fields to the XML to get rid of the 'Invalid argument supplied for foreach()' errors so I used the XML Schema Description to figure out where to add them. I ended up adding:

  • /store/manufacturers
  • /store/attributes
  • /store/classes
  • /store/products/product/attributes
  • /store/products/product/adjustments
  • /store/products/product/adjustments/adjustment

The /store/products/product/adjustment doesn't seem to be in the schema description but I managed to track down where to put it from the uc_importer.module.

There was an error in the exported XML file; there are two occurrences of <description/> in store/categories/category/ which I deleted.

3. Then I needed to sort out images so I created a directory on my server (set to 755, I'm sure less permissions would work but this was the default) and uploaded the image file. I changed the path to reflect the image file's path on the server, for me that was /var/www/html/import/image.jpg. This seems to work sometimes and other times just copies a 0 byte file with the correct name.

4. Delete your product and try to import the XML file you've just modified. Finger's cross it should be working for you without errors.

I hope I haven't missed anything and that this helps someone get their importing from XML working.

Here is the XML file that I've imported so you can compare it to your own:

<?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">
  <categories>
    <category>
      <id>1</id>
      <name>Accessories/Misc</name>
    </category>
    <category>
      <id>18</id>
      <name>EP82</name>
    </category>
  </categories>
  <manufacturers></manufacturers>
  <attributes></attributes>
  <classes></classes>
  <products>
    <product>
      <unique_hash>f560ab2ba8c286b1d64f7cdf39bae82b</unique_hash>
      <id>1</id>
      <type>product</type>
      <name>TRD Carbon Emblem</name>
      <description>Carbon Emblem E-Type by the Racing Development team from Toyota, TRD. This TRD carbon emblem is composed of real carbon fibre with silver print for the logo and will be a great addition to the interior or exterior of any Toyota vehicle.</description>
      <model>TOY-EMB-0001</model>
      <list_price>0.00</list_price>
      <cost>0.00</cost>
      <sell_price>10.00</sell_price>
      <weight>1</weight>
      <weight_units>Kilograms</weight_units>
      <image>
        <path>/var/www/html/import/trd_carbon_emblem.jpg</path>
        <alt>TRD Carbon Emblem</alt>
        <title>TRD Carbon Emblem</title>
      </image>
      <fields>
        <field>
          <name>field_application</name>
          <delta>
            <value>EP82 GT/EP91 Glanza/4efte/4efe</value>
          </delta>
        </field>
        <field>
          <name>field_extrainfo</name>
          <delta>
            <value>N/A</value>
          </delta>
        </field>
        <field>
          <name>field_deliveryinfo</name>
          <delta>
            <value>Free UK Mainland Delivery on all items.</value>
          </delta>
        </field>
      </fields>
      <categories>
        <category>
          <id>18</id>
        </category>
        <category>
          <id>1</id>
        </category>
      </categories>
      <attributes></attributes>
      <adjustments>
        <adjustment></adjustment>
      </adjustments>
    </product>
  </products>
</store>

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

rich,

regarding your import file example:

1) what is the difference between the category tags at the top of your file BEFORE you get to products tag and the categories that are children of the product tags?

2) and regarding question #1, is it possible that the "higher level" categories would need to "wrap"/"contain" a series of product tags and NOT be their siblings? follow?

thanks

Posts: 18
Joined: 09/14/2007
Bug Finder

1) the category tags at the top define the categories themselves, the category tags that are children of the product tags define which categories the product is a member of.

I had some trouble with images when importing a file for products that already existed. It seemed that they would sometimes disappear as I detailed here.

Glad to see Lyle is on the case. It looks like it takes quite a bit of work to keep this module up to date as features are added and changed.
-C

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

got it..

i didn't connect the dots. i assumed you already had to have your cats set up. but prepending them in the xml file takes care of that for you.

thanks

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

Hi druru, glad you got it working.