shopp('collection.has-products')

Determines whether the custom category, or collection, has displayable products, and loads product data.

shopp('collection', 'has-products', 'options')

@param string $object the object or object.tag combination, if object.tag is used, the tag parameter can be omitted
@param string $tag the tag, can be hyphenated or not. Prefix with 'get' as shorthand for the return=true option
@param mixed $options associative array, or url-style name=value pairs separated by ampersands (&). Each pair is passed to the theme api tag as an option.
@returns bool true if the collection has products, false if no products in the collection

Alternative Forms

shopp('collection.has-products', 'options...');

load-products tag is alias for has-products

shopp('collection', 'load-products', 'options...');

category object is the deprecated form

shopp('category', 'has-products', 'options...');

Description

This tag provides a simple test mechanism to allow different template layouts to be shown depending on whether there are any products available to display in the collection, and also loads the products for use by other Theme API calls if available.

Universal Options

All Theme API calls have these options.

  • return: when set to true, 1, or on, this option forces the tag to return the value instead of displaying/echoing the value to the page. Alternatively, prefix the tag parameter with get to get the same effect. All theme api tags that return a boolean value will return by default.
  • echo: when set to false, 0, or off, this option forces the tag to display the value to the page. This is the default for all non-boolean tags.
  • is: when set to true, 1, or on, this option will evaluate the return of the theme api call as a boolean true or false value. See how values are converted to boolean.

Options

The following options are valid:

  • load: (default: prices) comma separated string of product data to load. Each data type that is added to this list adds to the database loading overhead of the collection, as well as the memory used by the system to hold the data.

Load Option

  • prices: loads all variant pricing data into the product, and processes them all.
  • description: loads the product description data, which can be quite large for an entire collection of products on some sites, but is necessary if you will be using shopp(‘product’,’description’) on your collection pages. The product description is omitted by default on all collection pages.
  • summary: loads the product summary, which contains the product variant, product addon, and featured product settings, as well as cashed price ranges, stock levels, and product-wide shipping and tax flag. Without the summary, shopp(‘product’,’has-addons’) and shopp(‘product’,’has-variations’) will always return false, and you will not be able to iterate through product addons or variants in your collection templates. Also use if you need to determine if the product is featured, on sale, or out of stock.
  • categories: loads a product taxonomy term objects that the product is assigned to, including product categories, product tags, and customer product taxonomies. For backward compatibility, either the category or tag load option can be used to load all term objects.
  • tags: loads a product taxonomy term objects that the product is assigned to, including product categories, product tags, and customer product taxonomies. For backward compatibility, either the category or tag load option can be used to load all term objects.
  • meta: loads all product meta data. This load option will also load all images and product specs. For backwards compatibility specs and images can also be used, but all meta data will be loaded if any of the three load options appear.
  • images: loads all product meta data. This load option will also load all images and product specs. For backwards compatibility specs and images can also be used, but all meta data will be loaded if any of the three load options appear.
  • specs: loads all product meta data. This load option will also load all images and product specs. For backwards compatibility specs and images can also be used, but all meta data will be loaded if any of the three load options appear.
  • coverimages: loads only the primary or cover image for each product. Use this if you do not need other images and product meta data, and would like to keep the query stream-lined.

Examples

Basic content template example

<?php if(shopp('collection','has-products')): ?>
    <div>
    <?php while(shopp('collection','products')): ?>
        <h3><?php shopp('product','name'); ?></h3>
    <?php endwhile; ?>
    </div>
<?php else: ?>
    <p>There are no products for this category.</p>
<?php endif; ?>

Basic code example

// loads products if the collection has any
if ( shopp('collection','has-products') ) {

    // loop through products in the collection
    while ( shopp('collection','products') ) {
        // do product theme api calls here
    }
}

Loading only coverimages data

// load only product coverimages
if ( shopp('collection', 'has-products', 'load=coverimages')) {
    while ( shopp('collection','products') ) {
        // display product coverimages linked to product page
        $image = shopp('product','get-coverimage','setting=thumbnails');
        $url = shopp('product','get-url');
        $name = shopp('product','get-name');
        $content = $image ? $image : $name;

        echo '<a href="'.$url.'">'.$content.'</a>';
    }
}

Pre-loading product data example

$options = array(
    // specify collection product loading options
    'load' => 'description,summary,prices,summary,categories,meta'
);

// causes the above data to be loaded
if ( shopp('collection.hasproducts', $options) ) {
    while ( shopp('collection','products') ) {
        // works because loaded above
        shopp('product','description');

        // also will load images/meta/specs if not already loaded above
        if ( shopp('product','has-images') ) {
            while ( shopp('product','images') ) {
                // display all product images
                shopp('product','image','setting=collection');
            }
        }

        // depends on loading summary and/or prices
        if ( shopp('product','has-addons') ) {
            // loop through product addons here
        }
        if ( shopp('product','has-variations') ) {
            // loop through product variants here       
        }
        if ( shopp('product','has-savings') ) {
            // display savings
            shopp('product','savings');
        }

        // depends on loading categories or tags
        if ( shopp('product','has-categories') ) {
            // loop through product categories
        }
        if ( shopp('product','has-tags') ) {
            // loop through product tags
        }

        // depends on loading meta
        if ( shopp('product','has-specs') ) {
            // loop through product specs
        }
    }
}

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar