Results 1 to 2 of 2
  1. #1
    Join Date
    May 2007
    Posts
    214
    Plugin Contributions
    0

    Default 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

  2. #2
    Join Date
    Jan 2008
    Posts
    49
    Plugin Contributions
    0

    Default 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);
    }
    }
    }

 

 

Similar Threads

  1. Creating columns on main page for categories
    By helpme in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 22 May 2007, 05:14 PM
  2. Showing both categories of product (with multiple categories)
    By JakubM in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 29 Mar 2007, 11:48 PM
  3. Creating Custom Layouts for Categories
    By fostergross in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 14 Mar 2007, 10:09 AM
  4. Multiple webshops as categories
    By Marketman in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 25 Nov 2006, 10:57 PM
  5. Same product in multiple categories?
    By rstevenson in forum Setting Up Categories, Products, Attributes
    Replies: 7
    Last Post: 6 Nov 2006, 02:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •