Results 1 to 9 of 9

Thread: Total Products in Category and it descendants

  1. #1
    Join Date
    May 2006
    Posts
    190

    Default Total Products in Category and it descendants

    Has anyone got a hint or a how to on getting a list of all the products in a category and it's sub categories no matter the depth

    ie:

    Cat 1 ( sum of all of the cat 1.x products and sub categories)
    - Cat 1.1 ( sum of all of cat 1.1.x products)
    - Cat 1.1.1 (sum of all 1.1.1x products)
    - Cat 1.1.2 (sum of all 1.1.2x products)
    - Cat 1.2 (sum of all 1.2x products)

    I keep getting problems with it adding the sub sub categories to the categories totals
    if that makes sense

  2. #2
    Join Date
    Apr 2009
    Posts
    151

    Default

    This was covered in another thread, but sadly the solution (which works) I could not use.

    http://forums.aspdotnetstorefront.co...0107#post90107

    It seems you have to use an XML package to display product count, so if your skin uses custom/manually displayed category listings, it probably won't work for you.
    Running: AspDotNetStorefront ML 8.0.1.2/8.0.1.2

  3. #3
    Join Date
    May 2006
    Posts
    190

    Default

    That's great as far as it goes but it doesn't show the number of products in the ancestors.

    That shows something like
    Cat 1 (0)
    - Cat 1.1 (0)
    - - Cat 1.1.1(3)
    - - Cat 1.1.2(2)
    etc

    I want it to show
    Cat 1 (5)
    - Cat 1.1 (5)
    - - Cat 1.1.1(3)
    - - Cat 1.1.2(2)

  4. #4
    Join Date
    Apr 2009
    Posts
    151

    Default

    Did you make sure to reset your cache?

    I just tested it on my end and I am seeing the total number for all categories, including parent categories.
    Running: AspDotNetStorefront ML 8.0.1.2/8.0.1.2

  5. #5
    Join Date
    May 2006
    Posts
    190

    Default

    Yep everything restarted.

    It's not a standard XML Package, so I might be missing a recursive count somewhere

  6. #6
    Join Date
    Apr 2009
    Posts
    151

    Default

    Here's the package I used when I tested this. Maybe you can compare them and figure out what you're missing.

    Code:
    <?xml version="1.0" standalone="yes" ?>
    <!-- ###################################################################################################### -->
    <!-- Copyright AspDotNetStorefront.com, 1995-2009.  All Rights Reserved.					                -->
    <!-- http://www.aspdotnetstorefront.com														                -->
    <!-- For details on this license please visit  the product homepage at the URL above.		                -->
    <!-- THE ABOVE NOTICE MUST REMAIN INTACT.                                                                   -->
    <!-- ###################################################################################################### -->
    <package version="2.1" displayname="Categories" debug="false" includeentityhelper="true">
        <PackageTransform>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
                <xsl:output method="html" omit-xml-declaration="yes"/>
                <xsl:param name="CategoryID">
                    <xsl:choose>
                        <xsl:when test="/root/System/PageName = 'showmanufacturer.aspx' or /root/System/PageName = 'showsection.aspx' or /root/System/PageName = 'showdistributor.aspx' or /root/System/PageName = 'showvector.aspx' or /root/System/PageName = 'showgenre.aspx'">0</xsl:when>
                        <xsl:when test="/root/System/PageName = 'showcategory.aspx' and boolean(/root/QueryString/categoryid)">
                            <xsl:value-of select="/root/QueryString/categoryid"/>
                        </xsl:when>
                        <xsl:when test="(/root/System/PageName = 'showcategory.aspx' or /root/System/PageName = 'showproduct.aspx') and boolean(/root/Cookies/lastviewedentityinstanceid) and /root/Cookies/lastviewedentityname = 'Category'">
                            <xsl:value-of select="/root/Cookies/lastviewedentityinstanceid"/>
                        </xsl:when>
                        <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:param>
                <xsl:param name="AncestorID">
                    <xsl:for-each select="/root/EntityHelpers/Category//Entity[EntityID = $CategoryID]">
                        <xsl:value-of select="ancestor::*/EntityID"/>
                    </xsl:for-each>
                </xsl:param>
                <xsl:param name="ParentID">
                    <xsl:for-each select="/root/EntityHelpers/Category//Entity[EntityID = $CategoryID]">
                        <xsl:value-of select="parent::*/EntityID"/>
                    </xsl:for-each>
                </xsl:param>
                <xsl:template match="/">
                    <xsl:element name="ul">
                        <xsl:attribute name="class">
                            <![CDATA[tame]]>
                        </xsl:attribute>
    
                        <xsl:apply-templates select="/root/EntityHelpers/Category/Entity">
                            <xsl:with-param name="prefix" select="''"/>
                        </xsl:apply-templates>
    
                    </xsl:element>
                </xsl:template>
    			<xsl:template match="Entity">
                    <xsl:param name="prefix"></xsl:param>
                    <xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" />
                    <li class="tame">
                        <xsl:value-of select="$prefix" />
                        <xsl:if test="number(ParentEntityID) != 0">
                            <!-- <span class="catMark">&gt;&gt;</span>&#160; -->
                        </xsl:if>
                        <a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
                            <xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID">
                                <xsl:attribute name="style">font-weight:bold</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="$eName"/>
    						<!--output the number of products for this category-->
    						<xsl:value-of select="concat(' (', NumObjects, ')')" />						
                        </a>
    					<xsl:if test="count(child::Entity)&gt;0">
    	                    <!-- <xsl:if test="count(child::Entity)&gt;0 and (EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID)"> -->
                            <ul class="tame">
                                <xsl:apply-templates select="Entity">
                                    <!-- <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/> -->
                                </xsl:apply-templates>
                            </ul>
                        </xsl:if>
                    </li>
                </xsl:template>
            </xsl:stylesheet>
        </PackageTransform>
    </package>
    Running: AspDotNetStorefront ML 8.0.1.2/8.0.1.2

  7. #7
    Join Date
    May 2006
    Posts
    190

    Default

    I ran that in conjunction and I still get the number of products in the category, not in the descendants as well

  8. #8
    Join Date
    Apr 2009
    Posts
    151

    Default

    I think I see what may be happening here...The solution I provided will only tell you the number of products mapped to that category, regardless of level. I suppose I mis-read your original request.

    The easiest way I can think to do what you want to do (add 2 sub categories together and list that total in the parent category?) is to simply map all products in the sub categories to the parent category.

    Category 1 (299)
    -- Sub Category 1 (88) <---Map all these products to Category 1
    -- Sub Category 2 (199) <---Map all of these products to Category 1
    -- Sub Category 3 (12) <---Map all of these products to Category 1

    If you need Category 1 to remain empty, this obviously won't work for you. Although, there really is no reason to want it to remain empty...Why display that there are 200 products in the parent category when there really aren't any products there?

    Hope this helps.

    Edit: I am assuming you haven't mapped any products to the parent categories, otherwise you'd see the number of products in the parent category using the solution I linked to..
    Running: AspDotNetStorefront ML 8.0.1.2/8.0.1.2

  9. #9
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    432

    Default

    I noticed another thread with a similar question and posted a SQL statement that might get the data you need...

    http://forums.aspdotnetstorefront.co...ht=#post114777

Posting Permissions

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