products_collection
Allows to generate additional product collections with custom hashes.
Shop-Script
Input (passed by reference)
$params array Parameters.
$params['collection'] shopProductsCollection Instance of the product collection class.
$params['auto_title'] bool Flag requiring to apply a default text title to a product collection.
$params['add'] bool Flag requiring to add more collection generation conditions in case of repeated (recursive) call of shopProductsCollection class methods.
$params['collection'] shopProductsCollection Instance of the product collection class.
$params['auto_title'] bool Flag requiring to apply a default text title to a 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
$return
true
if a collection hash intended for this specific plugin is specified; false
otherwise. A hash must consist of the plugin identifier followed by a slash (/) character and extra parameters. Or only the identifier, without the slash and parameters if they are not required. Both these parts, the identifier and parameters, are returned as an array by method getHash()
of the shopProductsCollection
class instance, which is accessible by the collection key in the event handler’s input parameter.Shop-Script
Plugin code example
PHP
public function productsCollection($params) { /** @var shopProductsCollection */ $collection = $params['collection']; $hash = $collection->getHash(); // Accept only simple hash in this example; e.g., ?action=products#/products/hash=myplugin if (is_array($hash) && count($hash) == 1 && $hash[0] == $this->id) { //add your WHERE condition $collection->addWhere('...'); return true; } else { return false; } /* // Accept only complex hashes in this example; e.g., ?action=products#/products/hash=myplugin/foo if (count($hash) == 2 && $hash[0] == 'myplugin') { 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; } } */ }