Cart
Provides an interface to interact with cart state on the Rokt side.
see
Cart.onUpdateItem on how to be informed about item changes triggered on Rokt side.
see
Cart.setItems on how to set state of the cart.
Methods
getItems
▸ getItems(): ReadonlyArray‹CartItem›
Creates and returns a copy of the current state of Rokt cart. Each time the method is invoked a new copy is created.
Returns: ReadonlyArray‹CartItem›
onUpdateItem
▸ onUpdateItem(updateItemCallback
: function): void
Accepts a callback method to be triggered by Rokt whenever user updates an item in cart. The updated item state and the old item states are passed as a parameter to the callback method.
In case of user adding item to the cart for the first time old item state will be null. The same if user removes previously chosen item updatedItem will be null.
example
rokt.cart.updateItemCallback((updatedItem, oldItem) => {
// client logic to update cart state on client side
});
Parameters:
▪ updateItemCallback: function
Update item callback
▸ (updatedItem
: CartItem | null, oldItem
: CartItem | null): void
Parameters:
Name | Type |
---|---|
updatedItem | CartItem | null |
oldItem | CartItem | null |
Returns: void
setItems
▸ setItems(items
: Array‹CartItem›): void
Method used to set state of the cart on Rokt side. Useful during subsequent visits to a page where Rokt offers are displayed in order to initialise state of a cart based on current state hold on client side.
example
rokt.cart.setItems(cartItems);
Parameters:
Name | Type | Description |
---|---|---|
items | Array‹CartItem› | An array of cart items. |
Returns: void