Results 1 to 2 of 2
  1. #1
    Join Date
    May 2007
    Posts
    213
    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. v150 Creating Sub categories
    By StarrRaven in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 2 Sep 2012, 12:36 PM
  2. Copy Sub Categories To Multiple Main Categories
    By InSoMnIa in forum Setting Up Categories, Products, Attributes
    Replies: 18
    Last Post: 27 Jul 2012, 10:46 AM
  3. v139h Reorganizing products without creating new categories/sub categories?
    By jgold723 in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 30 Apr 2012, 06:50 PM
  4. Losing the footer when accessing categories with sub-categories
    By airscopes in forum Customization from the Admin
    Replies: 7
    Last Post: 22 Dec 2010, 07:26 PM
  5. An issue with Showing Top Categories AND Sub-categories
    By autoace in forum Customization from the Admin
    Replies: 0
    Last Post: 15 Sep 2009, 09:13 PM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR