Filtering Items in Oracle Commerce Cloud based on Inventory

Gregory Eschbacher
Oracle Developers
Published in
3 min readMay 31, 2019

By default, in Oracle Commerce Cloud all active products with a SKU and a price are indexed and returned by Search.

However, there are many times that a site wishes to only show items that are In-stock (or alternatively, that are not Out of Stock). This would be an example of a static record filter that can be configured in Search. This type of filtering would happen behind the scenes and remain off of the URL (such that customers can’t fiddle with the URL to show those products).

Each SKU is tagged with a field called “sku.availabilityStatus”. The set of distinct values for this field (as of 19B) is only:

  • INSTOCK
  • OUTOFSTOCK

Overall Steps

In our example, we will configure a filter to only show products that are sku.availabilityStatus = INSTOCK. To do so, we will:

  • GET /gsadmin/v1/cloud/pages/Default/services/guidedsearch
  • Modify the JSON for “recordFilters” in the @appFilterState section
  • PUT /gsadmin/v1/cloud/pages/Default/services/guidedsearch
  • Initiate publishing

Repeat these steps for /gsadmin/v1/cloud/pages/Default/services/typeahead

Modifying the appFilterState

After we perform a GET against /gsadmin/v1/cloud/pages/Default/services/guidedsearch, we can see a series of record filters already in place. Here is what the out of the box filtering looks like:

...
"@appFilterState": {
"hiddenNavigationFilter": "${catalogDimensionValueId}",
"@type": "FilterState",
"recordFilters": [
"product.active:1",
"sku.active:1",
"product.catalogId:${catalogId}"
],
"rollupKey": "sku.listingId"
},
...

The above filters can be modified, but we strongly suggest that you not do so as changes to the above will not be supported.

For our inventory filter, we would update it as follows:

"@appFilterState": {
"hiddenNavigationFilter": "${catalogDimensionValueId}",
"@type": "FilterState",
"recordFilters": [
"product.active:1",
"sku.active:1",
"product.catalogId:${catalogId}",
"sku.availabilityStatus:INSTOCK"
],
"rollupKey": "sku.listingId"
},

Publishing the changes

With that modified JSON, use PUT to place it back to /gsadmin/v1/cloud/pages/Default/services/guidedsearch. It also makes sense to update /typeahead as well so that there’s no mismatch between your full search results and typeahead results.

After the content has been PUT, we first want to verify that they are working. Log into OCC Admin and view your Preview Storefront. The filtering should now be in place when you perform keyword searches and navigate on search-driven pages.

When you are satisfied that the changes are working, the easiest thing to do is make a trivial change to a product (such as adding a space to a long description) and invoke Publishing. At the end of publishing, content changes (such as changes to Search configuration like /pages) will be promoted to the live Storefronts.

A few notes and caveats

  • Why isn’t this filter turned on out of the box? Not all customers use Oracle Commerce Cloud for inventory
  • If you use external inventory calls, you can’t use this for filtering (as external values aren’t indexed by Search)
  • Collections pages are not driven purely by search, and this filtering won’t affect them.

If you have other static filters that you would like to add, the above pattern should be of great assistance. There are a few key bits though:

  • The field sku.availabilityStatus already exists. If you do a GET against /gsadmin/v1/cloud/attributes.merge.json, you will see that this field is also enabled for “isRecordFilterable = true”.
  • If you define custom properties and wish to use them for filters, you would also need to set “isRecordFilterable” = true

Filters and URLs

Whenever you have a static filter such as sku.availabilityStatus, it is best to configure it as described in this guide. That filter won’t show up in URLs, and therefore can’t be fiddled with by shoppers.

The same type of filters can be added to the URL. For instance, the above filter could be added by appending &Nr=AND(sku.availabilityStatus:INSTOCK) to the URL. The downside is that it will be visible and can be fiddled with.

--

--

Gregory Eschbacher
Oracle Developers

technologist, Oracle Cloud architect, commerce specialist