Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
ccrz.ccApiProduct.fetch
Compatibility
This reference applies to:
Release | Managed Package Version | API Version |
---|---|---|
B2B Commerce for Visualforce Winter ’21 | 4.13 | 12 |
B2B Commerce for Visualforce Spring ’20 | 4.12 | 11 |
B2B Commerce for Visualforce Summer ’19 | 4.11 | 10 |
B2B Commerce for Visualforce Spring ’19 | 4.10 | 9 |
B2B Commerce for Visualforce Summer ’18 | 4.9 | 8 |
Signature
global static Map<String, Object> fetch(Map<String, Object>)
Service Layer Classes
- Data Service Provider
- ccrz.ccServiceProduct
- Logic Service Provider
- ccrz.ccLogicProductPricing
Inputs (Required)
Map<String, Object> that must include the following required keys:
- ccrz.ccApi.API_VERSION
- The version of the B2B Commerce for Visualforce API to reference for the method call. We recommend that you use the ccrz.ccApi.CURRENT_VERSION constant whenever possible, and only reference a specific version for compatibility if necessary.
Include either of the following keys, but not both. If you don't include either key, the method returns a ccrz.ccApi.MissingInputException.
- ccrz.ccApiProduct.PRODUCTIDLIST
-
Set<String> of specific product IDs to
query:
new Set<String>{'Product_ID_1', 'Product_ID_2'}
- ccrz.ccApiProduct.PRODUCTSKULIST
-
Set<String> of specific product SKUs to
query:
new Set<String>{'Product_SKU_1', 'Product_SKU_2'}
Inputs (Optional)
The input map can also include the following keys:
- ccrz.ccApi.API_SIZING
- Map<String, Object> that specifies the scope of data that this method returns, including which fields the method returns for each record that matches the query.
- ccrz.ccApiProduct.DATEFILTER
- Boolean
Value Usage true (default) Evaluate Start Date and End Date values when returning product data. false Ignore Start Date and End Date values when returning product data. - ccrz.ccApiProduct.INCLUDE_ATTRIBUTE_PRICING
- Boolean
Value Usage true Evaluate attribute data when ccrz.ccApiProduct.PARAM_INCLUDE_PRICING is also true. B2B Commerce for Visualforce calls the ccrz.ccLogicProductPricing logic service class, which: - Queries for ccrz__E_Attribute__c records that are related to each product
- Returns the attribute pricing JSON applied to the product's entitled price list item
false (default) Don't return any attribute pricing. - ccrz.ccApiProduct.MEDIAFILTER
- Set<String> of specific product media types that you want to return in the related ccrz__E_ProductMedia__c records.
- ccrz.ccApiProduct.PARAM_BY_ASC
- Boolean
Value Usage true Sort returned products by ID in ascending order. For example, sort from 100 to 900. If you pass ccrz.ccApiProduct.PARAM_BY_SEQ => true, products sort by Sequence value in ascending order. false (default) Sort returned products by ID in descending order. - ccrz.ccApiProduct.PARAM_BY_NULLS_LAST
- Boolean
Value Usage true Place all products with a null Sequence value at the end of the returned product data. false (default) Place all products with a null Sequence value at the beginning of the returned product data. - ccrz.ccApiProduct.PARAM_BY_SEQ
- Boolean
Value Usage true Sort returned products by Sequence value in descending order. For example, sort from 900 to 100. false (default) Sort returned products by ID in descending order. - ccrz.ccApiProduct.PARAM_INCLUDE_BLOCKED
- Boolean
Value Usage true Return products with any status. false (default) Return products with a status of only Released or Not Orderable. - ccrz.ccApiProduct.PARAM_INCLUDE_PRICING
- Boolean
Value Usage true (default) Include ccrz.ccApiProduct.PRODUCTPRICINGDATA in the product return data. B2B Commerce for Visualforce calls the ccrz.ccLogicProductPricing logic service class to evaluate each product's entitlements when determining pricing. false Don't return any pricing data. - ccrz.ccApiProduct.PARAM_INCLUDE_SELLERS
- Boolean
Value Usage true (default) Return a list of all sellers for each product. Make sure that ccrz.ccApiProduct.PARAM_INCLUDE_PRICING is also true. false Don't return any seller information. - ccrz.ccApiProduct.PARSE_ATTRIBUTE_PRICING
- Boolean
Value Usage true (default) Parse the attribute pricing JSON returned when ccrz.ccApiProduct.INCLUDE_ATTRIBUTE_PRICING is true. false Skip querying attribute records and return only an unparsed attribute pricing field from each product's entitled price list item. - ccrz.ccApiProduct.PRODUCTLOCALE
- String that specifies one of your storefront's supported locales. The method returns internationalized product values in the ccrz.ccApiProduct.PRODUCTLIST return key. The service layer translates the values from ccrz__E_ProductItemI18N__c records and handles fallback languages, if necessary.
- ccrz.ccApiProduct.PRODUCTSTOREFRONT
- String that specifies the name of a storefront for filtering the query.
- ccrz.ccApiProduct.TYPES
- Set<String> of specific product types to query for.
Outputs
Map<String, Object> that can include the following keys:
- ccrz.ccApi.API_VERSION
- Integer that indicates which API version was used for the query.
- ccrz.ccApi.SUCCESS
- Boolean
Value Usage true The call completed. false The call encountered errors. - ccrz.ccApiAttribute.IDS
- List<String> of entitled attribute records to pass to the ccrz.ccApiAttribute.fetch method for returning attributes related to the returned products. This data is available only when you include ccrz.ccApiProduct.PARAM_INCLUDE_PRICING => true in the input map.
- ccrz.ccApiProduct.PRODUCTLIST
- List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_Product__c that matches the query.
- ccrz.ccApiProduct.PRODUCTPRICINGDATA
- Map<String, Object> of the pricing data returned when you include ccrz.ccApiProduct.PARAM_INCLUDE_PRICING => true in the input map. This map contains seller, subscription term, attribute, and standard pricing information for the returned products.
- ccrz.ccApiSpec.SPECLIST
- List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_Spec__c record associated with product spec values, which are included in the productSpecs field of ccrz.ccApiProduct.PRODUCTLIST. For more information about fetching spec data, see ccrz.ccApiSpec.fetch.
- ccrz.ccApiSubProdTerm.SPTLIST
- List<Map<String, Object>> of subscription product terms related to the returned products.
- ccrz.ccApiSubProdTerm.SPTBYPRODID
- Map<String, Object> of subscription product terms per product.
Example
Query a pair of product IDs, and capture the first product's name in a variable.
Map<String, Object> productFetchQuery = new Map<String, Object>{
ccrz.ccApi.API_VERSION => ccrz.ccAPI.CURRENT_VERSION,
ccrz.ccApiProduct.PRODUCTIDLIST => new Set<String>{'Product_ID_1', 'Product_ID_2'},
ccrz.ccApi.SIZING => new Map<String, Object> {
ccrz.ccApiProduct.ENTITYNAME => new Map<String, Object> {
ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_S
}
}
};
try {
Map<String, Object> productFetchData = ccrz.ccApiProduct.fetch(productFetchQuery);
if (productFetchData.get(ccrz.ccApiProduct.PRODUCTLIST) != null) {
List<Map<String, Object>> myProductDataList = (List<Map<String, Object>>) productFetchData.get(ccrz.ccApiProduct.PRODUCTLIST);
String productName = (String) myProductDataList[0].get('sfdcName');
}
} catch (Exception e) {
// Error handling...
}
Platform Cache
By default, this method checks for product data previously queried and stored in Platform Cache. This design helps improve performance on your storefront when displaying your product data.
The underlying ccrz.ccServiceProduct.fetch method that supports the ccrz.ccApiProduct.fetch method checks the Platform Cache for product data.
- Before the ccrz.ccApiProduct.fetch method executes the query for product data, the underlying ccrz.ccServiceProduct.fetch data service method calls the ccrz.ccService.prepareCacheKey method.
- If ccrz.ccService.prepareCacheKey finds a match in Platform Cache for the queried data, it passes the matching data to the ccrz.ccService.prepReturn method, which sends the data to the ccrz.ccApiProduct.fetch query.
If no matching data is found in the Platform Cache, the ccrz.ccApiProduct.fetch query executes and returns data from your org's database. In this case, the ccrz.ccService.prepareCacheData method is called to store the product data in Platform Cache.
To specify how long B2B Commerce for Visualforce keeps product data cached, change the product data time to live (TTL) values in your storefront configuration settings.