CommerceCart Class

Get, create, update, and delete carts. Get cart items, add items to carts, update and delete cart items.

Namespace

ConnectApi

CommerceCart Methods

These methods are for CommerceCart. All methods are static.

addItemsToCart(webstoreId, effectiveAccountId, activeCartOrId, cartItems)

Add a batch of up to 100 items to a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.BatchResult[] addItemsToCart(String webstoreId, String effectiveAccountId, String activeCartOrId, List<ConnectApi.BatchInput> cartItems)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
cartItems
Type: List<ConnectApi.BatchInput>
The list can contain up to 100 ConnectApi.BatchInput objects. In the ConnectApi.BatchInput constructor, the input object must be ConnectApi.CartItemInput.

Return Value

Type: ConnectApi.BatchResult[]

The ConnectApi.BatchResult.getResult() method returns a ConnectApi.CartItem object.

The returned objects correspond to each of the input objects and are returned in the same order as the input objects.

The method call fails only if an error occurs that affects the entire operation (such as a parsing failure). If an individual object causes an error, the error is embedded within the ConnectApi.BatchResult list.

Usage

Buyers with read access to carts can add, update, and delete items in carts.

addItemToCart(webstoreId, effectiveAccountId, activeCartOrId, cartItemInput)

Add an item to a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItem addItemToCart(String webstoreId, String effectiveAccountId, String activeCartOrId, ConnectApi.CartItemInput cartItemInput)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
cartItemInput
Type: ConnectApi.CartItemInput
A ConnectApi.CartItemInput object representing an item to add to the cart.

Return Value

Type: ConnectApi.CartItem

Usage

Buyers with read access to carts can add, update, and delete items in carts.

createCart(webstoreId, cart)

Create a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartSummary createCart(String webstoreId, ConnectApi.CartInput cart)

Parameters

webstoreId
Type: String
ID of the webstore.
cart
Type: ConnectApi.CartInput
A ConnectApi.CartInput object representing a cart.

Return Value

Type: ConnectApi.CartSummary

Usage

Buyers with read access to carts can create and delete carts.

deleteCart(webstoreId, effectiveAccountId, activeCartOrId)

Delete a cart.

API Version

49.0

Requires Chatter

No

Signature

public static Void deleteCart(String webstoreId, String effectiveAccountId, String activeCartOrId)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.

Return Value

Type: Void

Usage

Buyers with read access to carts can create and delete carts.

deleteCartItem(webstoreId, effectiveAccountId, activeCartOrId, cartItemId)

Delete an item from a cart.

API Version

49.0

Requires Chatter

No

Signature

public static Void deleteCartItem(String webstoreId, String effectiveAccountId, String activeCartOrId, String cartItemId)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
cartItemId
Type: String
ID of the cart item.

Return Value

Type: Void

Usage

Buyers with read access to carts can add, update, and delete items in carts.

getCartItems(webstoreId, effectiveAccountId, activeCartOrId)

Get items in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItemCollection getCartItems(String webstoreId, String effectiveAccountId, String activeCartOrId)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.

Return Value

Type: ConnectApi.CartItemCollection

getCartItems(webstoreId, effectiveAccountId, activeCartOrId, pageParam)

Get a page of items in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItemCollection getCartItems(String webstoreId, String effectiveAccountId, String activeCartOrId, String pageParam)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.

Return Value

Type: ConnectApi.CartItemCollection

getCartItems(webstoreId, effectiveAccountId, activeCartOrId, pageParam, sortParam)

Get a sorted page of items in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItemCollection getCartItems(String webstoreId, String effectiveAccountId, String activeCartOrId, String pageParam, ConnectApi.CartItemSortOrder sortParam)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
sortParam
Type: ConnectApi.CartItemSortOrder
Sort order for items in a cart. Values are:
  • CreatedDateAsc—Sorts by oldest creation date.
  • CreatedDateDesc—Sorts by most recent creation date.
  • NameAsc—Sorts by name in ascending alphabetical order (A–Z).
  • NameDesc—Sorts by name in descending alphabetical order (Z–A).
  • SalesPriceAsc—Sorts from lowest to highest negotiated price.
  • SalesPriceDesc—Sorts from highest to lowest negotiated price.
If null, the default is CreatedDateDesc.

Return Value

Type: ConnectApi.CartItemCollection

getCartItems(webstoreId, effectiveAccountId, activeCartOrId, pageParam, pageSize)

Get a specified size page of items in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItemCollection getCartItems(String webstoreId, String effectiveAccountId, String activeCartOrId, String pageParam, Integer pageSize)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.

Return Value

Type: ConnectApi.CartItemCollection

getCartItems(webstoreId, effectiveAccountId, activeCartOrId, pageParam, pageSize, sortParam)

Get a specified size, sorted page of items in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItemCollection getCartItems(String webstoreId, String effectiveAccountId, String activeCartOrId, String pageParam, Integer pageSize, ConnectApi.CartItemSortOrder sortParam)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
sortParam
Type: ConnectApi.CartItemSortOrder
Sort order for items in a cart. Values are:
  • CreatedDateAsc—Sorts by oldest creation date.
  • CreatedDateDesc—Sorts by most recent creation date.
  • NameAsc—Sorts by name in ascending alphabetical order (A–Z).
  • NameDesc—Sorts by name in descending alphabetical order (Z–A).
  • SalesPriceAsc—Sorts from lowest to highest negotiated price.
  • SalesPriceDesc—Sorts from highest to lowest negotiated price.
If null, the default is CreatedDateDesc.

Return Value

Type: ConnectApi.CartItemCollection

getCartItems(webstoreId, effectiveAccountId, activeCartOrId, productFields, pageParam, pageSize, sortParam)

Get a specified size, sorted page of items filtered by product fields in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItemCollection getCartItems(String webstoreId, String effectiveAccountId, String activeCartOrId, String productFields, String pageParam, Integer pageSize, ConnectApi.CartItemSortOrder sortParam)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
productFields
Type: String
Comma-separated list of up to five product fields. Results include fields that you have access to. Some product fields (such as productName and sku) are returned even when not included in the productFields parameter.
pageParam
Type: String
Specifies the page token to be used to view a page of information. Page tokens are returned as part of the response class, such as currentPageToken or nextPageToken. If you pass in null, the first page is returned.
pageSize
Type: Integer
Specifies the number of items per page. Valid values are from 1 through 100. If you pass in null, the default size is 25.
sortParam
Type: ConnectApi.CartItemSortOrder
Sort order for items in a cart. Values are:
  • CreatedDateAsc—Sorts by oldest creation date.
  • CreatedDateDesc—Sorts by most recent creation date.
  • NameAsc—Sorts by name in ascending alphabetical order (A–Z).
  • NameDesc—Sorts by name in descending alphabetical order (Z–A).
  • SalesPriceAsc—Sorts from lowest to highest negotiated price.
  • SalesPriceDesc—Sorts from highest to lowest negotiated price.
If null, the default is CreatedDateDesc.

Return Value

Type: ConnectApi.CartItemCollection

getCartSummary(webstoreId, effectiveAccountId, activeCartOrId)

Get a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartSummary getCartSummary(String webstoreId, String effectiveAccountId, String activeCartOrId)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active. If you specify active and there isn’t an active cart, you get an error.

Return Value

Type: ConnectApi.CartSummary

getOrCreateActiveCartSummary(webstoreId, effectiveAccountId, activeCartOrId)

Get a cart or create an active cart if one doesn’t exist.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartSummary getOrCreateActiveCartSummary(String webstoreId, String effectiveAccountId, String activeCartOrId)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active. If you specify active and there isn’t an active cart, one is created.

Return Value

Type: ConnectApi.CartSummary

Usage

Buyers with read access to carts can create and delete carts.

updateCartItem(webstoreId, effectiveAccountId, activeCartOrId, cartItemId, cartItem)

Update an item in a cart.

API Version

49.0

Requires Chatter

No

Signature

public static ConnectApi.CartItem updateCartItem(String webstoreId, String effectiveAccountId, String activeCartOrId, String cartItemId, ConnectApi.CartItemInput cartItem)

Parameters

webstoreId
Type: String
ID of the webstore.
effectiveAccountId
Type: String
ID of the account for which the request is made. If null, defaults to the account ID for the context user.
activeCartOrId
Type: String
ID of the cart or active.
cartItemId
Type: String
ID of the cart item.
cartItem
Type: ConnectApi.CartItemInput
A ConnectApi.CartItemInput object representing a cart item to update.

Return Value

Type: ConnectApi.CartItem

Usage

Buyers with read access to carts can add, update, and delete items in carts.