Products

Getting product data

client
    .getProduct('https://selz.co/1rvbhT6')
    .then(product => {
        console.log('Product', product);
    })
    .catch(errors => console.error('Error getting product', errors));

Carts

Get all carts

client
    .getCarts()
    .then(carts => {
        console.log('Carts', carts);
    })
    .catch(errors => console.error('Error getting carts', errors));

Get active cart

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.

Getting a cart by currency

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));

Getting a cart by ID

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));

Creating a cart

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));

Add to a cart

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));

Update cart item quantity

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));

Remove from a cart

cart.remove(cartItem.index)
    .then(updatedCart => {
        console.log('Removed', updatedCart);
    })
    .catch(errors => console.error('Error removing from cart', errors));

Set active cart

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));