Basket
Commands
open
openOpens the basket.
instance.basket.open();close
closeCloses the basket.
instance.basket.close();getState
getStateGets the current state of the basket.
// You can either await the result of the command
const result = await instance.basket.getState();
// OR pass a callback
instance.basket.getState((result) => {
// YOUR CODE HERE
});The command will return an object with the following properties:
isOpen
boolean
Is the basket currently open
addProduct
addProductAdds a product to the basket. The command accepts a single argument, consisting of the properties below:
title
string
Product title
description
string
Product description
productId
string
Product Id
price
number
Product price
originPage
number
Page where the product is located on
quantity
number
Quanity of product to add
Below is an example use:
instance.basket.addProduct({
title: 'My product',
description: 'Product description',
productId: 'PROD-25B',
price: '29.95',
originPage: 6,
quantity: 1
});Events
onOpened
onOpenedThis subscription will trigger every time the basket is opened.
instance.basket.onOpened(() => {
// YOUR CODE HERE
});onClosed
onClosedThis subscription will trigger every time the basket is closed.
instance.basket.onClosed(() => {
// YOUR CODE HERE
});onToggled
onToggledThis subscription will trigger every time the basket is toggled between open and closed state.
instance.basket.onToggled(() => {
// YOUR CODE HERE
});onProductAdd
onProductAddThis subscription will trigger whenever a product is added to the basket.
Note:
Products added through the addProduct API command will not trigger this subscription.
instance.basket.onProductAdd((product) => {
// YOUR CODE HERE
});The callback contains a value/result of the product that was added, containing the following properties:
title
string
Product title
description
string
Product description
productId
string
Product ID
price
number
Product price
pageIndex
number
Page index where the product is located* (see note)
originPage
number
Page where the product is located on
quantity
number
Quanity of product added
packageSize
number
Number of items per package
Last updated