[SOLVED][Drupal CCK] "An error has occurred adding the content type " message is displayed when importing a product type from Ubercart

| | 2 min read

"An error has occurred adding the content type...Please check the errors displayed for more details.". This error usually occurs when you are importing an Ubercart product type to a content type using Drupal CCK and when you try to change the node name and type of the product in your Drupal website. Usually there will not be any other details of the error on display on the Drupal site when it has occurred. There is a fix for this error message and a solution to avoid it in the first place. Read on to find out more.

First let us look at the problem. If you try to export a product directly from Ubercart the array structure will look somewhat similar to this:

$content['type']  = array (
  'name' => 'Product',
  'type' => 'product',
................
.................
  'old_type' => 'product',
  'orig_type' => 'product',
  'module' => 'uc_product',
  'custom' => '0',
[... snip ...]
);

Now the thing is the uc_product module currently does not supply any methods to import the data in the correct format which is likely to be the cause of the error.

Now the solution

  • So you have to manually make changes to the the array structure to get it working again.
  • The product type should be imported only after changing the 'name', type', 'old_type', 'orig_type' to match the values of the new content type you want to make.
  • Next the most important change - Change the value of the 'module' key to 'node'. Some users have reported that this is the only thing you need to do.
  • Checkout the following example for product type books
  • $content['type']  = array (
      'name' => 'Book',
      'type' => 'book',
    [... snip ...]
      'old_type' => 'book',
      'orig_type' => 'book',
      'module' => 'node',
      'custom' => '0',
    [... snip ...]
    );
    
  • Now you can import your new content type
  • After successful importing it you will need to set the content type module back to uc_product via MYSQL using the sample code below.
  • mysql> update node_type set module="uc_product" where type="book";
    
    
  • If you want to create a new product class you will also need to do the following like this in your db:
  • mysql> insert into uc_product_classes (pcid,name,description) values ("book id","Name of the book","Description of the book");
    
    
  • Tip: You can also avoid the error by creating the product content type through Store Administration and then applying the CCK import.

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.