Forums / Templates, Stylesheets, Page Layout / Creating multiple categories with sub categories fast

Creating multiple categories with sub categories fast

Locked

Started by mcanes on 20 Jan 2008, 2:42 AM · Views: 1,482

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
20 Jan 2008, 2:42 AM
#1
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

Creating multiple categories with sub categories fast

Hello and good evening... I was wondering if anyone might know of a quick way to add categories and sub categories fast? Here is what I have ahead of me.

I am setting up a site that deal with NCAA Schools, so I will have about 100 categories (I currently have all the names in a spreadsheet) and each of these categories will have about 10 sub categories (this will be the same across all the schools). Basically it is alot of tedious work, so I didn't know if there was a quick way to tackle this. Example below.

University 1

  • Hats
  • Shorts
  • Shoes
  • Stickers
    University 2
  • Hats
  • Shorts
  • Shoes
  • Stickers
    University 3
  • Hats
  • Shorts
  • Shoes
  • Stickers

Since all the sub-categories are the same name I was hoping for a quick way to do this.

Thanks

7 Feb 2008, 7:35 PM
#2
enigmabomb avatar

enigmabomb

New Zenner

Join Date:
Jan 2008
Posts:
49
Plugin Contributions:
0

Re: Creating multiple categories with sub categories fast

If youre brave with PHP, and have a test installation to play with:

Run from admin, include application_top.php and this function returns the ID of the cat it creates.

Bon appetite

function add_cat($currentid, $catname, $catdesc)
{
global $db;
$sort_order = "";
$current_category_id = $currentid;
$sql_data_array = array('sort_order' => (int)$sort_order);
$insert_sql_data = array('parent_id' => $current_category_id,
'date_added' => 'now()');

$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
zen_db_perform(TABLE_CATEGORIES, $sql_data_array);
$categories_id = zen_db_insert_id();
echo "making new cat, ID: ".$categories_id."under $currentid <br>";
// check if [arent is restricted
$sql = "select parent_id from " . TABLE_CATEGORIES . "
where categories_id = '" . $categories_id . "'";
$parent_cat = $db->Execute($sql);
if ($parent_cat->fields['parent_id'] != '0') {
$sql = "select * from " . TABLE_PRODUCT_TYPES_TO_CATEGORY . "
where category_id = '" . $parent_cat->fields['parent_id'] . "'";
$has_type = $db->Execute($sql);
if ($has_type->RecordCount() > 0 ) {
while (!$has_type->EOF) {
$insert_sql_data = array('category_id' => $categories_id,
'product_type_id' => $has_type->fields['product_type_id']);
zen_db_perform(TABLE_PRODUCT_TYPES_TO_CATEGORY, $insert_sql_data);
$has_type->moveNext();
}
}
}

$languages = zen_get_languages();
//echo "There are $languages languages\n<br>";
//print_r($languages);

for ($i=0, $n=sizeof($languages); $i<$n; $i++)
{
$categories_name_array[1] = $catname;
$categories_description_array[1] = $catdesc;
$language_id = $languages[$i]['id'];

// clean $categories_description when blank or just <p /> left behind
$sql_data_array = array('categories_name' => zen_db_prepare_input($categories_name_array[$language_id]),
'categories_description' => ($categories_description_array[$language_id] == '<p />' ? '' : zen_db_prepare_input($categories_description_array[$language_id])));
$action = 'insert_category';
if ($action == 'insert_category')
{
$insert_sql_data = array('categories_id' => $categories_id,
'language_id' => $languages[$i]['id']);
$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
zen_db_perform(TABLE_CATEGORIES_DESCRIPTION, $sql_data_array);
//echo "added $catname <br>\n";
return($categories_id);
}
}
}