Understanding asynchronous calls and caching

Current version: 9.3

How the Commerce Search Results rendering and the Product List rendering handle asynchronous calls and caching is different. It is important to understand the differences so that you make an informed decision when choosing which rendering to use.

Commerce Search Results rendering AJAX calls

The Commerce Search Results rendering makes two asynchronous JavaScript and XML (AJAX) calls when rendering a list of catalog items:

  • The first call queries the index and retrieves a list of items to render. This call originates from the SXA Search Results rendering (on which this rendering is based) and is made to the SXA Search Service that returns the catalog items as HTML markup. These are processed server-side by the rendering variant. Because the list of catalog items and the product content remain relatively stable, caching this call is recommended.

  • The second call is commerce specific and occurs after retrieving the markup for the list of catalog items and is made to the Commerce Engine to retrieve the price and stock information for the list of products. This call cannot be made in parallel with the first one because one of its query parameters, the list of Product IDs, is reliant on the response data retrieved from the first call. The call is only made once the list of Product IDs is populated and is no longer empty. When the price and stock information is received, it is bound to the markup using Knockout JS binding and is updated accordingly. The data attributes price and stockLabel specifically will now show their binding data values. The second call is located in the catalog-commerce-search-results-model script stored in /sitecore/Media library/Base Themes/Commerce Components Theme/Scripts/Catalog/catalog-commerce-search-results-model/. Because the price and stock information is more likely to change often, deciding to cache this call and for how long is a business decision.

To improve performance, you can cache one or both the AJAX calls by using a Content Delivery Network (CDN). However, be aware that when you use the Commerce Business Tools to change prices either directly on products or on price cards, or you add promotions for specific products that are cached using CDN, there is no way to force the CDN cache to be cleared from XC. You must do this separately or as part of custom scripts or a custom integration with the business tools.

First call - SXA Search Service AJAX call

This SXA Search Service AJAX call queries the index and retrieves the list of items to render. This call is made to the SXA Search Service that returns the items as HTML markup, processed server side by the rendering variant.

Full URL: http://[host name]/sxa/search/results/?l=[language]&s=[scope]&itemid=[current item id]& sig=[search result signature]&p=[page size]&o=[sort order]&v=[rendering variant id]

Example: http://mqa-ts-02-dk1//sxa/search/results/?l=en& s={9DCE2EF2-EE0C-4C02-B2ED-A8769FC08C3B}& itemid={994EC8CB-FE90-5071-A631-4458B1E83DB3}& sig=category-page& p=12& o=Display name,Ascending& v={175DC0A7-7214-450A-8765-688D62A551D1}

Http method: GET

The following table details the parameters used in this call.

Parameters

Use

l

To specify the language version of the results.

s

To specify the scope item will be used for filtering the results.

itemid

The current context item ID.

sig

The commerce search result signature.

p

The page size.

o

The ordering of the results for a specific field in ascending or descending order.

v

The variant definition ID.

Second call - GetSellableItemsSummary AJAX call

The GetSellableItemsSummary call retrieves the price and stock information for the list of products by calling the commerce components layer. Data is returned in JSON format.

Full URL: https://[host name]/api/cxa/Catalog/GetSellableItemsSummary?sc_site=[site name]

Example: https://mqa-ts-02-dk1/api/cxa/Catalog/GetSellableItemsSummary?sc_site=Storefront

Http method: POST

The following table details the parameters used in this call.

Parameters

Use

itemIds

To specify the product ID and the catalog name for the list of products.

Example: Habitat_Master|6042976|

includeBundledItems

To include bundle items in the results.

Example: true

Product List and Promoted Products AJAX calls

Unlike the Commerce Search Results rendering, the Product List rendering makes only one AJAX call. This call retrieves both product content as well as price and stock information and returns it as JSON that is bound to HTML markup using Knockout JS. The Product List rendering has built-in support for AJAX call caching, which is handled at the CD instance level.

The Promoted Products rendering is very similar to the Product List rendering except in the way the product list is retrieved and that it does not support built-in AJAX call caching.

Note

Both renderings support AJAX call caching when using a Content Delivery Networks (CDN) to take advantage of the distributed and geo-location caching abilities that come with it. CDN caching is superior to built-in caching because static resources are stored on servers more local to the user. When caching of the AJAX call is turned on, both content as well as price and stock information is cached. This makes it less flexible than the Commerce Search Results rendering where product content can be cached separately from retrieving price and stock information.

GetProductList Ajax call

The GetProductList Ajax call queries the index and retrieves the list of items to render along with the price and stock information for the list of products in JSON format. The call is made to the commerce components layer.

Full URL: http://[host name]/api/cxa/catalog/GetProductList?sc_site=[site name]

Example: http://mqa-ts-02-dk1/api/cxa/catalog/GetProductList?sc_site=Storefront

Http method: POST

The following table details the parameters used in this call.

Parameters

Use

pg

To specify the page.

ps

To specify the page size.

sd

The sort direction (asc / dsc).

cci

ci

Do you have some feedback for us?

If you have suggestions for improving this article,