JSMA products

Overview

The JSMA products provides functionality for finding products.

What can JSMA products do for me?

You could easily use the JSMA products to find products

Index

Methods

The JSMA products provides the following methods:

product[] products.find(query, [options={}])

The function signature products.find(query, [limit], [star]) is deprecated and will produce a warning in log files.

Finds an array of  products (JSMA product) by a given query with extended Sphinx syntax.

Example

...
//search for products with wildcard enabled
var p = products.find(query, { limit: 1000, page: 2 });

var pOld = products.find(args[0], args[1], true); // deprecated
...

Parameter string query

Parameter options:object (optional)

Default for limit will be 10 if no value is provided.

products.findById(id)

Finds a product by its id.

Avoid usage of findById

Ids change whenever a package is reimported. So please avoid using ids whenever possible. Also delivering contents to users by id might make it possible for users to flip through the files (and by that see contents of others possibly) by changing the ids in requests.

Example

...
var prod = products.findById(123);
...

Parameter int id

products.findByName(name)

Finds a product by its name.

Example

...
function main ()
{
  var path = request.path;
  
  //retrieve substring after last /
  var productName = path.substring(path.lastIndexOf("/") + 1);
  
  //retrieve product from db
  var product = products.findByName(productName);
  
  //check if the product was found and then store it in the request
  if (product !== null) {
    request.set("test.products.currentProduct", product);
  }
}
...

Parameter string name

The name of the product