/product/search.json
Query searchable Product objects via Ajax returned as JSON.
For familiarity we have tried to ensure consistency in terminology with ProductSearch.
Example using JQuery
jQuery.getJSON('/product/search.json', function(returnValue) {
console.log(returnValue);
} );
Internationalisation
If your website has multiple languages you will want to ensure search results are returned in the language, country and currency of your locales. To achieve this you can localise the URL as follows.
In your EVML view file:
<div id="myDiv" data-url="@/product/search.json"></div>
Within your view's JavaScript file:
var myDiv = jQuery('#myDiv');
jQuery.getJSON(myDiv.attr('data-url'), function(returnValue) {
console.log(returnValue);
} );
With the code above it won't matter which locale you visit the URL and results will be correct.
Accepted Parameters
The search script allows you to define the following optional parameters.
category
Allows you to filter product results within a single category tree, where the value of the parameter is the category ID. Products will be returned if they are associated directly with the category ID supplied, or are associated with any of the category's nested descendants. |
category:in
Allows you to filter products associated with one of more category IDs. Products will be returned if they are associated directly with the category IDs supplied. Category IDs may supplied as an array or as a comma separated list. |
featured
Find products that are featured by supplying the |
fragment
An EVML include/partial to render per result. You may supply one fragment to render only. The fragment path
should be supplied in the format |
id:in
Filter results by one or more Product IDs, supplied as an array or comma separated list. |
sort
Column and direction to sort results. Adheres to orderable values of ProductSearch.orderBy().
Defaults to 'title:asc'.
|
page
The page of results to return.
|
limit
The number of results to show per page. Defaults to 10.
|
price
The price parameter must include |
q
Define a search string.
|
Returned Object
The search script returns an object with the following properties.
category
|
fragments
If you specify a |
isFirstPage
|
isLastPage
|
nextPage
The number of the next page in the result set, or |
nextPageUrl
The URL of the next page in the result set, or |
orderBy
The sort order of the results. Adheres to orderable values of ProductSearch.orderBy(). |
page
The number of the current page (starts at 1 for first page). |
perPage
The number of results returned per page. |
phrase
The search phrase supplied by the |
previousPage
The number of the previous page in the result set, or |
previousPageUrl
The URL of the previous page in the result set, or |
results
A JSON array with each element (if any) containing an flattended representation of a Product object. Note that only basic settings may be available by comparison to the full Product Object. |
success
|
total
The total number of matching results for the search across all pages. |
totalPages
The total number of pages available in the result set. |