Created
April 18, 2024 08:51
-
-
Save ranveer5289/d0346574fe272ac1956355d2947885fe to your computer and use it in GitHub Desktop.
Commerce_Endpoint_Search_ProductSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class CommerceEndpointSearchProductSearch extends ConnectApi.BaseEndpointExtension { | |
public override ConnectApi.EndpointExtensionRequest beforePost(ConnectApi.EndpointExtensionRequest request) { | |
System.debug('We are in the beforePost entry method of Commerce_Endpoint_Search_ProductSearch extension'); | |
return request; | |
} | |
public override ConnectApi.EndpointExtensionResponse afterPost(ConnectApi.EndpointExtensionResponse response, ConnectApi.EndpointExtensionRequest request) { | |
System.debug('We are in the afterPost entry method of Commerce_Endpoint_Search_ProductSearch extension'); | |
System.debug('response.getResponseObject()-----' + response.getResponseObject()); | |
ConnectApi.ProductSearchResults results = (ConnectApi.ProductSearchResults)response.getResponseObject(); | |
List<ConnectApi.SearchFacet> originalFacets = (List<ConnectApi.SearchFacet>)results.facets; | |
for (ConnectApi.SearchFacet facet : originalFacets) { | |
String id = facet.nameOrId; | |
System.debug('nameOrId----' + id); | |
if (id == 'OrderSeasonYear__c') { // just an example | |
ConnectApi.DistinctValueSearchFacet myFacet = (ConnectApi.DistinctValueSearchFacet)facet; | |
List<ConnectApi.DistinctFacetValue> faceValues = myFacet.values; | |
// apply custom sorting on cloned facet values and set it back again. How to sort ConnectAPI results? | |
// myFacet.values = faceValues; - throws an EXCEPTION System.UnsupportedOperationException: Output properties may only be written in objects built for tests | |
System.debug('facetValues----' + faceValues); | |
} | |
} | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment