ccrz.ccApiCart.fetch

Executes a SOQL query of cart records, and returns a list of carts that match your query.

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

You can still call older versions of the API for this method, which can accept different input keys or return different output keys. Any differences in behavior for older versions aren't documented in this topic.

Note

Signature

global static Map<String, Object> fetch(Map<String, Object>)

Service Layer Classes

Data Service Provider
ccrz.ccServiceCart

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.

If this key isn't specified, the method returns a ccrz.ccApi.NoApiVersionException.

Note

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.ccApiCart.ACTIVECART
Boolean
Value Usage
true Return the active cart for a specific owner. Use this key with when you also specify ccrz.ccApiCart.BYOWNER.
false (default) Return all carts that match the other query criteria.
ccrz.ccApiCart.BYOWNER
String that specifies the ID of a specific user. Return only cart records where the Owner field matches this user ID.

Sharing rules in your org can affect what data you can see when you filter by cart owner.

Note

ccrz.ccApiCart.BYUSER
String that specifies the ID of a specific user. Return only cart records where the User field matches this user ID.

Sharing rules in your org can affect what data you can see when you filter by user.

Note

ccrz.ccApiCart.BYSTOREFRONT
String that specifies the name of a storefront for filtering the query.

If the input data doesn't include this key, the method falls back to ccrz.cc_CallContext.storefront.

Note

ccrz.ccApiCart.CART_ENCID
String that specifies the encrypted ID of the cart to query.
ccrz.ccApiCart.CART_ENCIDLIST
Set<String> of encrypted cart IDs to query.
ccrz.ccApiCart.CART_IDLIST
Set<String> of cart IDs to query.

This key takes precedence over ccrz.ccApiCart.CART_ENCID or ccrz.ccApiCart.CART_ENCIDLIST. If you specify both ccrz.ccApiCart.CART_IDLIST and ccrz.ccApiCart.CART_ENCIDLIST, this method ignores ccrz.ccApiCart.CART_ENCIDLIST.

Note

ccrz.ccApiCart.CARTNAME
String that specifies a cart name to query. This value corresponds to the Cart Auto Number (Name) field on the cart record.
ccrz.ccApiCart.CARTSTATUS
String that specifies a cart status for filtering records in the return data. This value corresponds to the ccrz__CartStatus__c field on the cart record.
ccrz.ccApiCart.CARTTYPE
Deprecated. The managed package no longer references this key.
ccrz.ccService.SEARCHSTRING
String that specifies filter criteria to pass to the ccrz.ccApiCart.fetchCartItems method.

This input is available only in B2B Commerce for Visualforce Winter ’21 (managed package version 4.13 and API version 12).

Note

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.

B2B Commerce for Visualforce doesn't always return an exception for any errors that can occur. When this value is false, consider rolling back the API transaction to a previous savepoint.

Tip

ccrz.ccApiAddress.ADDRESSLIST
List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_ContactAddr__c associated with the cart's shipping or billing addresses. For more information about fetching address data, see ccrz.ccApiAddress.fetch.

To specify which fields the API returns for each contact address, request a specific data size for the ccrz.ccApiAddress.ENTITYNAME key in your input data. You can request unique sizes for cart data and contact address data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiCart.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M
    },
    ccrz.ccApiAddress.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_L
    }
}

You can also exclude the address records from the return data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiCart.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M,
        ccrz.ccApi.SZ_ASSC => false
    }
}

Tip

ccrz.ccApiCart.CART_OBJLIST
List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_Cart__c record that matches the query. By default, this list sorts by each cart's last modified date in descending order.

To specify which fields the API returns for each cart record, request a specific data size for the ccrz.ccApiCart.ENTITYNAME key in your input data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiCart.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M
    }
}

For information about which fields are available with different data sizes, see the ccrz__E_Cart__c reference.

Tip

ccrz.ccApiProduct.PRODUCTLIST
List<Map<String, Object>>, where each Map<String, Object> represents a ccrz__E_Product__c associated with the cart's items. For more information about fetching product data, see ccrz.ccApiProduct.fetch.

To specify which fields the API returns for each product record, request a specific data size for the ccrz.ccApiProduct.ENTITYNAME key in your input data. You can request unique sizes for cart data and product data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiCart.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M
    },
    ccrz.ccApiProduct.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_L
    }
}

You can also exclude the product records from the return data:

ccrz.ccApi.SIZING => new Map<String, Object> {
    ccrz.ccApiCart.ENTITYNAME => new Map<String, Object> {
        ccrz.ccApi.SZ_DATA => ccrz.ccApi.SZ_M,
        ccrz.ccApi.SZ_ASSC => false
    }
}

Tip

Examples

Query a pair of cart IDs, and capture the first cart's status in a variable.

Set<String> cartIdList = new Set<String>{'CART_ID_1', 'CART_ID_2'};
 
Map<String, Object> cartFetchQuery = new Map<String, Object>{
   ccrz.ccApiCart.CART_IDLIST => cartIdList,
   ccrz.ccApi.API_VERSION => ccrz.ccApi.CURRENT_VERSION
};
 
try {
    Map<String, Object> cartFetchData = ccrz.ccApiCart.fetch(cartFetchQuery);
    if (cartFetchData.get(ccrz.ccApiCart.CART_OBJLIST) != null) {
        List<Map<String, Object>> outputCartList = (List<Map<String, Object>>) cartFetchData.get(ccrz.ccApiCart.CART_OBJLIST);
        String firstCartStatus = (String) outputCartList[0].get('cartStatus');
    }
} catch (Exception e) {
    // Error handling...
}

Query all carts with a status of Abandoned.

Map<String, Object> cartFetchQuery = new Map<String, Object>{
   ccrz.ccApiCart.CARTSTATUS => 'Abandoned',
   ccrz.ccApi.API_VERSION => ccrz.ccApi.CURRENT_VERSION
};
 
try {
    Map<String, Object> cartFetchData = ccrz.ccApiCart.fetch(cartFetchQuery);
    if (cartFetchData.get(ccrz.ccApiCart.CART_OBJLIST) != null) {
        List<Map<String, Object>> outputCartList = (List<Map<String, Object>>) cartFetchData.get(ccrz.ccApiCart.CART_OBJLIST);
    }
} catch (Exception e) {
    // Error handling...
}