1 reply [Last post]
haggis's picture
Offline
Joined: 02/22/2009
Juice: 27
Was this information Helpful?

Hello,
I wanna code a module which adds a new product class (+ node type) at its installation. I tried several ways including db_query() but nothing worked as it should.

Now I'm trying to simulate a users uc_ubercart_class_form_submit but it also doesn't work Sad

Here's my code:

<?php

function uc_mymodule_install() {
 
$form_state['values']['name'] = 'Moduletestclass';
 
$form_state['values']['pcid'] = 'moduletestclass';
 
$form_state['values']['description'] = 'Moduletestclass description blablabla';
 
$form['pcid']['#type'] = 'textfield';
 
module_invoke_all(class_form_submit,$form, $form_state);
}
?>

The only thing that happens is a redirect to 'admin/store/products/classes' as in ubercarts hook_class_form_submit() defined. What did I forget?

Did anyone created an ubercart module which adds a new product class + some cck fields?

Every suggestion is welcome!

greetz haggis

haggis's picture
Offline
Joined: 02/22/2009
Juice: 27
Wohoo!

Got it!

<?php
function uc_mymodule_install() {

// Product class testclass
 
db_query("INSERT INTO {uc_product_classes} (pcid, name, description) VALUES ('testclass', 'Testclass', 'Just another stupid description.')");

 

uc_product_node_info(TRUE);
  if (
module_exists('imagefield')) {
   
uc_product_add_default_image_field('testclass');
  }

 

// add cck fields using content_copy
 
ob_start();
  include
'cck_event.inc';
 
ob_end_clean();

 

$form_state['values']['type_name'] = 'testclass';
 
$form_state['values']['macro'] = '$content = '. var_export($content, 1) .';';
 
$form_state['values']['op'] = t('Import');
 
drupal_execute('content_copy_import_form', $form_state);

 

menu_rebuild();
?>