Getting subcategory totals [shopp(‘subcategory’,’total’)] to work in Shopp Plugin 1.1.*

Problem: Pulling the total number of products from a subcat in Shopp doesn’t seem to work out the box. For example, this code WON’T return the total even though the correct tag shopp(‘subcategory’,’total’) is used:

<?php while(shopp('category','subcategories')): ?>
    <?php shopp('subcategory','name'); ?> (<?php shopp('subcategory','total'); ?>)
<?php endwhile; ?>

Fix: For the products to be countable, the ‘hasproducts‘ tag has to be called with the ‘load’ option like so:

<?php while(shopp('category','subcategories')): ?>
    <?php if(shopp('subcategory','hasproducts','load=prices,images')): ?>
        <?php shopp('subcategory','name'); ?> (<?php shopp('subcategory','total'); ?>)
    <?php endif; ?>
<?php endwhile; ?>

Note: The docs refer to ‘category’ tags. Each category tag has an ideantical subcategory tag. For example <?php shopp('category','name'); ?> and <?php shopp('subcategory','name'); ?> both work when used in the correct context.

Leave a Reply

Your email address will not be published. Required fields are marked *