<%@ Language=VBScript %> <% '************************************************************************* ' DO NOT MODIFY THIS SCRIPT IF YOU WANT UPDATES TO WORK! ' Function : Category Maintenance ' Product : CandyPress Store Administration ' Version : 2.5 ' Modified : February 2004 ' Copyright: Copyright (C) 2004 CandyPress.Com ' See "license.txt" for this product for details regarding ' licensing, usage, disclaimers, distribution and general ' copyright requirements. If you don't have a copy of this ' file, you may request one at webmaster@candypress.com '************************************************************************* Option explicit Response.Buffer = true const adminLevel = 1 %> <% 'Database dim mySQL, cn, rs 'Categories dim idCategory dim categoryDesc dim idParentCategory dim categoryFeatured dim categoryHTML dim sortOrder '************************************************************************* 'Open Database Connection call openDB() 'Store Configuration if loadConfig() = false then response.redirect "sysMsg.asp?errMsg=" & server.URLEncode("Could not load Store Configuration settings.") end if 'Set Row Colors dim rowColor, col1, col2 col1 = "#DDDDDD" col2 = "#EEEEEE" %>

Category Maintenance

<% if len(trim(Request.QueryString("msg"))) > 0 then %> <%=Request.QueryString("msg")%>

<% end if 'Check if the Root Category (idParentCategory=0) exists mySQL="SELECT idCategory " _ & "FROM categories " _ & "WHERE idParentCategory = 0 " set rs = openRSexecute(mySQL) if rs.eof then call closeRS(rs) %>

The store requires one "Root" Category.


Would you like to create a Root Category now? [ Yes | No ]


<% Response.End end if call closeRS(rs) 'Retrieve all Categories mySQL="SELECT a.idCategory, a.categoryDesc, " _ & " a.idParentCategory, a.categoryFeatured, " _ & " a.sortOrder, " _ & " (SELECT b.categoryDesc " _ & " FROM categories b " _ & " WHERE b.idCategory = a.idParentCategory) " _ & " AS ParentCategoryDesc " _ & "FROM categories a " _ & "ORDER BY a.idParentCategory, a.sortOrder, a.CategoryDesc" set rs = openRSexecute(mySQL) %>
Add New Category

<% rowColor = col1 %> <% rowColor = col2 rs.MoveFirst do while not rs.eof %> <% if rs("idParentCategory") = 0 then %> <% elseif isNull(rs("ParentCategoryDesc")) or rs("ParentCategoryDesc") = "" then %> <% else %> <% end if %> <% rs.movenext 'Switch Row Color if rowColor = col2 then rowColor = col1 else rowColor = col2 end if loop %> <% call closeRS(rs) %>
 
ID Category Parent Category Sort Feat.  
<%=rs("idCategory")%> <%=rs("categoryDesc")%><ROOT>--> None--> <%=rs("ParentCategoryDesc")%><%=emptyString(rs("SortOrder"),"-")%> <%=rs("categoryFeatured")%> [ ">edit | ">test ] <% if rs("idParentCategory") = 0 then Response.Write " " else Response.Write "" end if %>
Delete Selected Categories?

Help and Instructions :
Example - You can have as many Categories within Categories (Sub-Categories) as you want.
  • Category 1
    • Product 1
    • Product 2
  • Category 2
    • Category 3
      • Category 4
        • Product 3
        • Product 4
  • Category 5
Step By Step - To create the above category structure, you would create Category 1 first and link it to the Root Category. Then you would create Category 2 and link it to the Root Category. Next you would create Category 3 and link it to Category 2. After that you would create Category 4 and link it to Category 3. Lastly you would create Category 5 and link it to the Root Category. Once the Categories have been set up, you can then start linking Products to their required Categories.

Basic Rules - Some of the basic rules regarding Categories are listed below :

  1. You can NOT link a Category to another Category that :

    • Has Products linked to it. In the above example, you will not be able to link a Category to Categories 1 or 4. You will have to un-link the Products from these Categories first.

    • Is already a Sub-Category of the Category. In the example above, you will not be able to link Category 2 to Category 3 as it's already a Sub-Category of Category 2.

  2. The Category Description can be anything you want, even if that Description is already used with another Category.

  3. Deleting a Category will not automatically delete any Sub-Categories or Products linked to it. These Sub-Categories and Products will merely be un-linked from the deleted Category. Categories not currently linked to a Parent Category will be marked in red on this list and should ideally be deleted also, or re-linked to other Categories. So, in the example above, deleting Category 3 will NOT delete Category 4 (or any of it's Products). However, if you list the Category "tree", the listing will only include Categories 1,2 and 5. Category 4 will not be displayed as it's no longer linked to anything.

  4. There is no physical limitation on the number of Sub-Category levels you can create. It is however adviseable not to create a Category structure that is more than 5 levels "deep" as it may have an impact on your server's performance.
Test Category - Click on "test" to see what your Category will look like when it's accessed through your store front. When you Test a Category that has Sub-Categories, you should see a list of all the Sub-Categories. If the Category being tested has Products linked to it, you will see the Product list for that Category (if you don't have any Products linked to the Category yet, you will just see a message to that affect).

<% 'Close the Database Connection call closedb() %>