<img src="https://secure.leadforensics.com/84962.png" style="display:none;">

Category listing

You can implement category navigation using Loop54. This is a fast and easy way to retrieve products and can also be extended with features such as faceting, custom sorting, personal or aggregated popularity sorting and more. 

Code examples
SHOW INSTRUCTIONS FOR: PHP JSON JAVA .NET
Below is an example of a request - response cycle of an category listing request request.
$request = new Loop54_Request("ProductsInCategory");
$request->setValue("RequestEntity",new Loop54_Entity("Category",$_GET{"category"}));
$request->setValue("ProductsInCategory_FromIndex", 0);
$request->setValue("ProductsInCategory_ToIndex", 9);
$response = Loop54_RequestHandling::getResponse("http://helloworld.54proxy.com", $request);
if ($response->success)
{
    if($response->hasData("ProductsInCategory"))
    {
        $results = $response->getCollection("ProductsInCategory");
        if(count($results)==0)
            echo "There were no items in this category.";

        foreach($results as $resultItem)
        {
            $productId = $resultItem->key->externalId;
            $productTitle = $resultItem->key->getStringAttribute("Title");
            echo $productId . " " . $productTitle; //render a product on the category listing page
        }
    } 
}
else
{
    echo $response->requestId; //log this
}
Below is an example of a request - response cycle of an category listing request request.
POST to  http://helloworld.54proxy.com/productsincategory
{
    "UserId" : "helloworlduser",
    "IP" : "127.0.0.1",

    "RequestEntity":{
        "EntityType":"Category",
        "ExternalId":"Fruit"
    },

    "ProductsInCategory_FromIndex" : 0,
    "ProductsInCategory_ToIndex" : 9,
}

Response: 200 OK
{
  "Success": true,
  "HeroId": "The Count with not enough Writing Sisters",
  "Data": {
    "ProductsInCategory": [
      {
        "Key": {
          "ExternalId": "1",
          "EntityType": "Product",
          "Attributes": {
            "Manufacturer": [
              "The banana company"
            ],
            "Category": [
              "Fruit"
            ],
            "Title": [
              "Banana"
            ],
            "SubCategory": [
              "Musaceae"
            ]
          }
        },
        "Value": 1
      },
      {
        "Key": {
          "ExternalId": "7",
          "EntityType": "Product",
          "Attributes": {
            "Manufacturer": [
              "The banana company"
            ],
            "Category": [
              "Fruit"
            ],
            "Title": [
              "Organic Apple"
            ],
            "SubCategory": [
              "Rosaceae"
            ]
          }
        },
        "Value": 0
      },
      {
        "Key": {
          "ExternalId": "3",
          "EntityType": "Product",
          "Attributes": {
            "Manufacturer": [
              "Fruits n Veggies"
            ],
            "Category": [
              "Fruit"
            ],
            "Title": [
              "Apple"
            ],
            "SubCategory": [
              "Rosaceae"
            ]
          }
        },
        "Value": 0
      },
      {
        "Key": {
          "ExternalId": "17",
          "EntityType": "Product",
          "Attributes": {
            "Manufacturer": [
              "Fruits n Veggies"
            ],
            "Category": [
              "Fruit"
            ],
            "Title": [
              "Orange"
            ],
            "SubCategory": [
              "Citrus"
            ]
          }
        },
        "Value": 0
      }
    ]
  }
}
Below is an example of a request - response cycle of an category listing request request.
Request loopRequest = new Request("ProductsInCategory",request,response);
loopRequest.setValue("RequestEntity", new Entity("Category",request.getParameterValues("category")[0]));
loopRequest.setValue("ProductsInCategory_FromIndex", 0);
loopRequest.setValue("ProductsInCategory_ToIndex", 9);
Response loopResponse = RequestHandling.getResponse("http://helloworld.54proxy.com", loopRequest);
if (loopResponse.success)
{
    if(loopResponse.hasData("ProductsInCategory"))
    {
        ArrayList results = loopResponse.getItemArray("ProductsInCategory");
        if(results.isEmpty())
            response.getWriter().print("There were no items in this category.");

        for(Item resultItem: loopResponse.getItemArray("ProductsInCategory"))
        {
            String productId = ((Entity)resultItem.key).externalId;
            String productTitle = ((Entity)resultItem.key).getAttribute("Title").firstValue();
            response.getWriter().print(productId + " " + productTitle); //render a product on the category listing page
        }
    }
}
else
{
    response.getWriter().print("ERROR: " + loopResponse.requestId); //keep track of unsuccessful requests
}
Below is an example of a request - response cycle of an category listing request request.
var request = new Loop54.Request("ProductsInCategory");
request.SetValue("RequestEntity", new Loop54.Model.Entity("Category", Request.QueryString["category"]));
request.SetValue("ProductsInCategory_FromIndex", 0);
request.SetValue("ProductsInCategory_ToIndex", 9);
var response = Loop54.RequestHandling.GetResponse("http://helloworld.54proxy.com", request);

if (response.Success)
{
    var results = response.GetValue<List<Item<Entity>>>("ProductsInCategory");
    if (!results.Any())
        Response.Write("There were no items in this category.");

    foreach (var resultItem in results)
    {
        var productId = resultItem.Key.ExternalId;
        var productTitle = resultItem.Key.Attributes["Title"].FirstOrDefault() as string;
        Response.Write(productId + " " + productTitle + Environment.NewLine); //render a product on the category listing page
    }
}
else
{
    Response.Write("ERROR: " + response.RequestId + Environment.NewLine);
}

Parameters

  • RequestEntity: The category for which to fetch products. In "EntityType" + "ExternalId" format.
  • Paging: The results can be separated into pages using FromIndex and ToIndex (inclusive). Asking for ProductsInCategory_FromIndex : 0 and ProductsInCategory_ToIndex : 9 will yield 10 results. 
  • Descriptives: IP and UserId (If you are using a library, the library should take care of this).