Product Search Ajax API Improvements
New filtering options added to the Product Search Ajax API improve the capabilities of client-side search.
New parameters accepted within the Product Search Ajax API allow theme developers to improve user-centric front-end functionality, or help implement features dropped from our server-side EVML templates due to our recent whole page caching update.
Filtering by Product IDs
Finding products explicitly by their IDs using the new id:in
parameter
is useful in a number of scenarios. For example, efficiently implementing "Recently viewed" functionality.
Let's assume we want to obtain basic product data for Products with IDs 123 and 456. We can GET JSON representing these products
by supplying their IDs as a comma separated list to the id:in
parameter. For example, using
jQuery your query may look something like this:
jQuery.getJSON('/product/search.json?id:in=123,456', function(returnValue) {
console.log(returnValue);
} );
Finding products within one or more categories
You can now filter product results within a single category and all of its sub-categories using the new category
parameter.
Alternatively, if you need to target one or more categories explicitly (excluding their descendants), you can supply
a comma separated list of category IDs to the category:in
parameter.
In the example below we intend to find products associated with the current Category only, with an ID of 754.
jQuery.getJSON('/product/search.json?category:in=754', function(returnValue) {
console.log(returnValue);
} );
Typically, you would use category
or category:in
independently
and not in conjunction.
Price filtering
You can now filter products based on price. Although this requires both price[min]
and
price[max]
parameters to be supplied, you can supply an empty value to min/max for open ended filtering.
For example, you may wish to find all products under a certain value. Let's say you wanted to find products under £100 (assuming this
is the currency of the site's current locale).
jQuery.getJSON('/product/search.json?price[max]=100&price[min]=', function(returnValue) {
console.log(returnValue);
} );
Including or excluding featured products
You can now request or exlcude featured products from search results using the featured
parameter.
Supplying a value of true
will limit results to only featured products,
whilst supplying a false
value will exclude them.
Closing thoughts
The new parameters outlined above may be used independently or in combination - allowing you to build targeted functionality. For example, you may wish to obtain featured products within a specific category.
Find full reference documentation on the Product Search Ajax API page.
We hope to continue to improve functionality across our Ajax APIs to address the growing need for implementing more sophisticated client-side features.
Get the knowledge and inspiration
Get the knowledge and inspiration you need to build a profitable business — straight to your inbox.
Unsubscribe any time! / Privacy Policy