1 reply [Last post]
betz's picture
Offline
Joined: 07/03/2009
Juice: 8
Was this information Helpful?

Hey,

i see there's no function for getting all product classes from ubercart.
But in the db table i only see newly created product classes.
What about the basic product nodetype?

I am building a modulke where you need to select a product class, but now you only see the extra created classes (and so nodetypes).

Now i want to know what's the best way to work... Do i manually add the original product nodetype to the list of product classes in my array?
Doesn't sounds very good, but i don't see a other way for the moment.

What you suggest?

grtz,
tom

tcindie@drupal.org's picture
Offline
Getting busy with the Ubercode.
Joined: 05/15/2008
Juice: 440
Re: product classes in db

That's how I handled it in the power tools module.. Manually adding the 'product' class to the list of available product class types..

here's my code:

<?php
    
 
// Get a list of all product classes.
 
$result = db_query('SELECT pcid, name from {uc_product_classes}');
  while (
$classes = db_fetch_array($result)) {
   
$productclasses[$classes['pcid']] = $classes['name'];
  }

 

// Add entry for Default Products to end of the list:
 
$productclasses['product'] = 'Default Ubercart Product Content Type';
      
?>

This way I wind up with an array ($productclasses) with each of the array keys being the id of a product class and its value being the human readable name...

If all you need are the pcid's and not the human readable names, try something like this:

<?php
  
 
// Create and array for all product classes. Fill first element with default 'product' class type:
 
$productclasses = array();
 
$productclasses[] = 'product'
 
 
// Get a list of all product classes.
 
$result = db_query('SELECT pcid, name from {uc_product_classes}');
  while (
$classes = db_fetch_array($result)) {
   
$productclasses[] = $classes['pcid'];
  }      
?>

which would give you an array with integer keys, and pcid as their value.. the default product class in this scenario will always be $productclasses[0]

Follow me on twitter.