products_collection

Creation of custom product collections for displaying in backend or frontend.

Shop-Script

Input (passed by reference)

$params array Parameters.
$params['collection'] shopProductsCollection Instance of product collection class.
$params['auto_title'] bool Flag requiring to apply a default text title to product collection.
$params['add'] bool Flag requiring to add more collection generation conditions in case of repeated (recursive) call of shopProductsCollection class methods.
… your plugin code …

Output

true if a collection hash intended for this specific plugin was specified; false otherwise. The URL for creating product collections must have the form ?action=products#/products/hash=*** The value of 'hash' parameter in the URL must be specified as one or two string identifiers separated by a slash /. Identifiers contained in the hash are available the in the hook handler in the form of an array returned by method getHash() of class shopProductsCollection.

Shop-Script

Plugin code example

PHP

public function productsCollection($params)
{
    $collection = $params['collection'];
    $hash = $collection->getHash();
    if (count($hash) == 1 && $hash[0] == 'myplugin') {    //accept only simple hash in this example; e.g., ?action=products#/products/hash=myplugin
        $collection->addWhere('...'); //add your WHERE condition
        return true;
    } else {
        return false;
    }
    /*
    if (count($hash) == 2 && $hash[0] == 'myplugin') {    //accept only complex hashes in this example; e.g., ?action=products#/products/hash=myplugin/foo
        switch ($hash[1]) {
            case 'foo':
                $collection->addWhere('...'); //add a WHERE condition
                return true;
            case 'bar':
                $collection->addWhere('...'); //add another WHERE condition
                return true;
            default:
                return false;
        }
    }
    */
}