Parameters
Single item (simple)
Single item (with options)
Multiple items
Returns
Promise<ShopifyCart>
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Add items to the cart
openbridge.cart.add(variantId, quantity)
openbridge.cart.add(variantId, options)
openbridge.cart.add(lines)
| Param | Type | Required | Description |
|---|---|---|---|
variantId | string | Yes | Product variant GID |
quantity | number | No | Quantity to add (default: 1) |
| Param | Type | Required | Description |
|---|---|---|---|
variantId | string | Yes | Product variant GID |
options.quantity | number | No | Quantity to add (default: 1) |
options.sellingPlanId | string | No | Selling plan GID for pre-orders/subscriptions |
| Param | Type | Required | Description |
|---|---|---|---|
lines | CartLineInput[] | Yes | Array of line items |
Promise<ShopifyCart>
await openbridge.cart.add('gid://shopify/ProductVariant/123')
await openbridge.cart.add('gid://shopify/ProductVariant/123', 3)
await openbridge.cart.add([
{ merchandiseId: 'gid://shopify/ProductVariant/123', quantity: 2 },
{ merchandiseId: 'gid://shopify/ProductVariant/456', quantity: 1 }
])
// After fetching a product
const product = await openbridge.products.get('awesome-tshirt')
const variant = product.variants[0]
await openbridge.cart.add(variant.id, 1)
document.querySelector('.add-to-cart').addEventListener('click', async (e) => {
const variantId = e.currentTarget.dataset.variantId
const quantity = parseInt(e.currentTarget.dataset.quantity) || 1
await openbridge.cart.add(variantId, quantity)
})
await openbridge.cart.add('gid://shopify/ProductVariant/123', {
quantity: 1,
sellingPlanId: 'gid://shopify/SellingPlan/456'
})
await openbridge.cart.add([
{
merchandiseId: 'gid://shopify/ProductVariant/123',
quantity: 1,
sellingPlanId: 'gid://shopify/SellingPlan/456'
},
{
merchandiseId: 'gid://shopify/ProductVariant/789',
quantity: 2
}
])
const lines = openbridge.cart.lines()
lines.forEach(line => {
if (line.sellingPlanAllocation) {
console.log('Plan:', line.sellingPlanAllocation.sellingPlan.name)
console.log('Deposit:', line.sellingPlanAllocation.checkoutChargeAmount.amount)
console.log('Remaining:', line.sellingPlanAllocation.remainingBalanceChargeAmount.amount)
}
})