How to import products into Drupal Ubercart with a Script

So, you've setup you brand new Drupal install with Ubercart, and now you want to import your products into the store's database. However, much to your disappointment, you can't find anything that tells you how to do that. As always, the lack of examples makes such a task seem impossible, but in reality it's very simple.

I spent about 2 weeks doing research and trying out code with trial and error, trying to figure this out. I was successful, and I will save you the trouble. Welcome to the much needed tutorial on How to import products into Drupal Ubercart with a Script. With this tutorial, you will import products and categories from an outside data source, and keep them synchronized.

Requirements

First Things first, make sure you meet the minimum prerequisites:

  • Drupal 5.x with Ubercart 1.x Module installed
  • PHP 5.x
  • CCK
  • CCK Node Reference
  • CCK Image Field
  • CCK Text Field
  • CCK Number Field (optional)
  • Image Cache
  • Image Field

Design and Structure

For this tutorial, we will use an example book store, and 4 different data files. I have abstracted the data file structures as 4 different PHP data structures (classes/objects). This is meant to keep the focus on the Drupal end of things and not the parsing of the data file.

At minimum each book needs to have the following key pieces of information.

  • Author
  • Title
  • Description
  • Cover Image
  • Price
  • ISBN #
  • Product SKU

We also need to provide categories to organize the store catalog. Ubercart and Drupal handle this ingeniously by utilizing the Taxonomy feature. So, we will create a vocabulary called "Subject" and import the categories from our data files as terms.

PacyWorld Button
Powered by Pacy