client
.getProduct('https://selz.co/1rvbhT6')
.then(product => {
console.log('Product', product);
})
.catch(errors => console.error('Error getting product', errors));
client
.getCarts()
.then(carts => {
console.log('Carts', carts);
})
.catch(errors => console.error('Error getting carts', errors));
The cart that has the last interaction (added to or removed from).
client
.getActiveCart(true)
.then(cart => {
console.log('Cart', cart);
})
.catch(errors => console.error('Error getting active cart', errors));
If you don't want to fetch the whole cart, you can pass an bool argument of false
to just return the basic cart details which will be faster.
Note: If you try to get a cart by currency code and it doesn't exist, we'll create one for you anyway.
client
.getCartByCurrency('USD')
.then(cart => {
console.log('Cart', cart);
})
.catch(errors => console.error('Error getting cart', errors));
You can also fetch by ObjectId (cart.id
)...
client
.getCartById(id)
.then(cart => {
console.log('Cart', cart);
})
.catch(errors => console.error('Error getting cart', errors));
You can also manually create a cart yourself but you shouldn't need to in the majority of cases.
client
.createCart('USD')
.then(cart => {
console.log('Cart', cart);
})
.catch(errors => console.error('Error creating cart', errors));
cart.add({
id: product.id,
quantity: 3,
variant_id: product.variants[0].id,
})
.then(updatedCart => {
console.log('Added', updatedCart);
})
.catch(errors => console.error('Error adding to cart', errors));
There are two ways to update the quantity of an item in the shopping cart. Firstly, using the method:
client
.updateCartItemQuantity(cart.id, cartItem.index, 2)
.then(updatedCart => {
console.log('Updated', updatedCart);
})
.catch(errors => console.error('Error updating quantity', errors));
cart.remove(cartItem.index)
.then(updatedCart => {
console.log('Removed', updatedCart);
})
.catch(errors => console.error('Error removing from cart', errors));
If you're building your own UI and wish to set the last active cart (for when you want to call .getActiveCart
later). The argument passed can be either a card ID or a currency code.
client
.setActiveCart('USD')
.then(cart => {
console.log('Set active cart', cart);
})
.catch(errors => console.error('Error setting active cart', errors));