Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 6 of 6

Thread: Include Category Description in Category Description

  1. #1
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default Include Category Description in Category Description

    I have two sub-categories that will contain the same products, but need to appear under different parent categories. I was wondering if there was a way to assign categories to multiple parents like products can be assigned to multiple categories.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  2. #2
    jjdunkel is offline Member
    Join Date
    Jan 2006
    Location
    Chicago
    Posts
    78

    Default

    Not without some custom programming and database changes.

  3. #3
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    Database changes? What kind of database changes?
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  4. #4
    jjdunkel is offline Member
    Join Date
    Jan 2006
    Location
    Chicago
    Posts
    78

    Default

    Well right now the database is setup so that all categories/sub categories are all in one table. Each category has a CategoryID and a ParentCategoryID. Root categories have a 0 in ParentCategoryID, meaning they have no parent. A sub-category would have the CategoryID of the category it's listed under as it's ParentCategoryID. This setup allows you to have infinite levels of sub-categories.

    With what you are trying to do, you would need to give a category 2 parent id's so if you know that you will only ever need the same category in 2 parent categories, you could, I suppose, add another field to the category table and then update all the stored procedures, class files, entity helpers, etc.

    If you would need a category to have unlimited parent categories you would want to change the database structure to more like how a product is included into multiple categories, then change all the stored procedures, class files, entity helpers, etc.

    ------------------- BUT ------------------------------------

    If you are just trying to save yourself from maintaining the products that are included in two different categories(that just happen to have the same name), I think we can find a much simpler solution.

    You could maintain one category then run a sql statement on the database to copy all the products in one category to another.

    Code:
    DELETE FROM ProductCategory
    WHERE CategoryID = *CategoryID you want to copy TO*
    
    INSERT INTO ProductCategory
    (CategoryID,ProductID)
    SELECT *CategoryID you want to copy TO*, ProductID
    FROM ProductCategory
    WHERE CategoryID = *CategoryID you want to copy FROM*
    The first statement deletes all products that are in the category you want to copy to, because you don't want duplicates when you do the copy.

    The second statement copies all products into the second category.

  5. #5
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I like your SQL solution. I assume the same approach could work for the Description of the category as well.

    Thanks.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  6. #6
    jjdunkel is offline Member
    Join Date
    Jan 2006
    Location
    Chicago
    Posts
    78

    Default

    You could do something like:

    Code:
    UPDATE Category
    Set Description = (SELECT Description FROM Category WHERE CategoryID = *CategoryID to copy FROM*)
    WHERE CategoryID = *CategoryID to copy TO*

    Or you could copy and paste the description from one category to another