Category listings

Code examples for category listings.

Facets, Filtering and Sorting

Facets can be applied to category listings in a similar way to search. Have a look at the facets guide for more details.

Custom filtering and sorting options are also available for category listings. Have a look at the sorting and filtering guide for more details.

Example

The example shows how to list products in a category. The call is structured much like a search call and the parameters work in the same way so have a look at the explanation of search parameters if you’re unsure how they work.

Other than that, listing categories is simply a matter of calling GetEntitiesByAttribute and supplying the name of the category that you want to list.

// Below is an example of a request - response cycle of a category listing request
var request = new GetEntitiesByAttributeRequest("Category", categoryName);
request.ResultsOptions.Skip = 0;
request.ResultsOptions.Take = 9;

var response = _loop54Client.GetEntitiesByAttribute(request);

var results = response.Results.Items;

if (!results.Any())
    Debug.WriteLine("There were no items in this category.");

foreach (var resultItem in results)
{
    var productId = resultItem.GetAttributeValueOrDefault<string>("Id");
    var productTitle = resultItem.GetAttributeValueOrDefault<string>("Title");
    Debug.WriteLine(productId + " " + productTitle);
    //render a product on the category listing page
}
C# source code on Github: CategoryListingController.cs
// Below is an example of a request - response cycle of a category listing request

GetEntitiesByAttributeRequest request = new GetEntitiesByAttributeRequest("Category", categoryName);
request.resultsOptions.skip = 0;
request.resultsOptions.take = 9;

GetEntitiesByAttributeResponse response = loop54Client.getEntitiesByAttribute(request);
List<Entity> results = response.results.items;

if (response.results.count == 0)
  System.out.println("There were no items in this category.");

for(Entity resultItem : results)
{
  String productId = resultItem.id;

  String productTitle = resultItem.getAttributeValueOrNull("title", String.class);
  System.out.println(productId + " " + productTitle);
  //render a product on the category listing page
}
Java source code on Github: CategoryListingController.java
// Below is an example of a request - response cycle of a category listing request
var response = client.getEntitiesByAttribute("Category", categoryName, {skip: 0, take:9}).then((r) => {
    var data = r.data
        var results = data["results"].items;
        
        if (!results || results.length == 0)
        {
        console.log("There were no items in this category.");
        }
        else
        {
        console.log("Total number of items: " + data["results"].count);
        for (var i in results)
        {
            var productId = results[i].id;
            var productTitle = results[i].attributes ? results[i].attributes.find(function(a){return a.name=="Title"}).values[0] : "";
            console.log(productId + " " + productTitle); //render a product on the category listing page
        }
        }    
}
);
JavaScript source code on Github: categorylisting.js
/* Configure a request to get the 9 first items in the Meat category */
$request = $connector->getEntitiesByAttribute('Category', 'Meat');
$request->resultsOptions()
->skip(0)
->take(9);

/* Actually perform the request */
$response = $connector->query($request);

/* Print all results in this response. */
echo 'Items in category:' . PHP_EOL;
foreach ($response->getResults() as $entity) {
$id = $entity->getId();
$title = $entity->getAttribute('Title');
echo $id . ': ' . $title . PHP_EOL;
}
PHP source code on Github: Simple.php