Trying to get the sum of all of a particular variable assigned in the subcategory foreach loop.
Basically, I would like to get the sum of each subcategory's product count so it can be displayed as the total number of products available from all the subcategories combined.
Working on an alternate CTGY template for "Parent Categories" that will show 4 featured products from each subcategory rather than assigning products manually to the parent categories.
There will be a view all button that links to the subcategory underneath each set/section of 4 subcategory products for ease of navigation if the user would like to explore more without having to scroll to the top where the original subcategory listing is, which will still be retained (Code above).
Thanks in advance.
Code:
<mvt:foreach array="cattree_categories" iterator="cattree_category"> <mvt:if expr="l.settings:cattree_category:parent_id EQ l.settings:category:id"> <mvt:assign name="l.null" value="miva_array_insert(l.settings:subcats, l.settings:cattree_category, -1)" /> </mvt:if> </mvt:foreach> <mvt:assign name="l.settings:subcat_count" value="miva_array_elements( l.settings:subcats )" /> <mvt:foreach iterator="sub_category" array="subcats"> <mvt:do name="l.success" file="g.Module_Library_DB" value="Category_Load_Code( l.settings:sub_category:code, l.settings:current_subcat )" /> <mvt:do name="l.success" file="g.Module_Library_DB" value="Runtime_ProductList_Load_Offset_Category( l.settings:current_subcat:id, g.Offset, 500, g.NextOffset, l.settings:sub_products )" /> <mvt:comment>assign variable that outputs the number of products in each subcategory</mvt:comment> <mvt:assign name="l.settings:subprods_count" value="miva_array_elements( l.settings:sub_products )" /> <mvt:comment>This is where I can't figure out how to get the sum of each subcategory product count variable assigned above.</mvt:comment> <mvt:assign name="l.settings:subprods_total_count" value="l.settings:subprods_count + l.settings:subprods_count" /> <mvt:assign name="l.settings:featured_subprods" value="4" /> <a href="&mvt:sub_category:link;" aria-label="&mvte:sub_category:name;"> <figure class="nm"> <div class="place-holder"> <img class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" width="102" height="102" data-src="&mvt:sub_category:image;" alt="&mvte:sub_category:name;"/> </div> <figcaption>&mvt:sub_category:name; (&mvt:subprods_count;)</figcaption> </figure> </a> <mvt:assign name="l.settings:current_subcat" value="''"/> <mvt:assign name="l.settings:sub_products" value="''"/> </mvt:foreach> <h2>Featured Gifts</h2> <mvt:assign name="l.settings:featured_subprods_count" value="l.settings:subcat_count * l.settings:featured_subprods" /> <p>&mvt:featured_subprods_count; of &mvt:subprods_total_count; Products</p>
Working on an alternate CTGY template for "Parent Categories" that will show 4 featured products from each subcategory rather than assigning products manually to the parent categories.
There will be a view all button that links to the subcategory underneath each set/section of 4 subcategory products for ease of navigation if the user would like to explore more without having to scroll to the top where the original subcategory listing is, which will still be retained (Code above).
Thanks in advance.
Comment