openbridge.products.get(idOrHandle)
openbridge.products.get(idOrHandle).select(fields)
.select() to limit fields.
Parameters
| Param | Type | Required | Description |
|---|---|---|---|
idOrHandle | string | Yes | Product handle or GID |
Supported formats
| Format | Example |
|---|---|
| Handle | 'blue-shirt' |
| Shopify GID | 'gid://shopify/Product/8834792939738' |
Returns
ShopifyProduct | null
Returns null if product not found.
Examples
By handle
const product = await openbridge.products.get('classic-cotton-shirt')
if (product) {
console.log(product.title)
console.log(product.priceRange.minVariantPrice.amount)
}
By GID
const product = await openbridge.products.get(
'gid://shopify/Product/8834792939738'
)
With field selection
const product = await openbridge.products
.get('classic-cotton-shirt')
.select(['title', 'handle', 'priceRange', 'variants', 'options'])
Access variants
const product = await openbridge.products
.get('classic-cotton-shirt')
.select(['title', 'variants'])
product?.variants.forEach((variant) => {
console.log(variant.id)
console.log(variant.title)
console.log(variant.price.amount)
console.log(variant.availableForSale)
})
Find specific variant
const product = await openbridge.products
.get('classic-cotton-shirt')
.select(['variants'])
const variant = product?.variants.find(
(v) =>
v.selectedOptions.some(
(opt) => opt.name === 'Size' && opt.value === 'M'
) &&
v.selectedOptions.some(
(opt) => opt.name === 'Color' && opt.value === 'Blue'
)
)
console.log(variant?.id) // Use for cart
console.log(variant?.price.amount)
Access options
const product = await openbridge.products
.get('classic-cotton-shirt')
.select(['options'])
product?.options.forEach((option) => {
console.log(option.name) // "Size", "Color"
console.log(option.values) // ["S", "M", "L"], ["Blue", "Red"]
})
Handle not found
const product = await openbridge.products.get('non-existent-product')
if (!product) {
console.log('Product not found')
}
Get selling plans (pre-orders)
Fetch a product’s selling plans to enable pre-order or subscription purchases.const product = await openbridge.products
.get('limited-edition-sneaker')
.select(['title', 'variants', 'sellingPlanGroups'])
// Check if product has selling plans
if (product?.sellingPlanGroups.length > 0) {
const group = product.sellingPlanGroups[0]
const plan = group.sellingPlans[0]
console.log(plan.id) // 'gid://shopify/SellingPlan/123'
console.log(plan.name) // '$50 deposit'
// Add to cart with selling plan
await openbridge.cart.add(product.variants[0].id, {
quantity: 1,
sellingPlanId: plan.id
})
}
Display selling plan options
const product = await openbridge.products
.get('subscription-box')
.select(['sellingPlanGroups'])
product?.sellingPlanGroups.forEach((group) => {
console.log('Group:', group.name)
group.sellingPlans.forEach((plan) => {
console.log(' Plan:', plan.name)
console.log(' ID:', plan.id)
// Checkout charge info (deposit amount)
if (plan.checkoutCharge.type === 'PERCENTAGE') {
console.log(' Deposit:', plan.checkoutCharge.value.percentage + '%')
} else {
console.log(' Deposit:', plan.checkoutCharge.value.amount?.amount)
}
})
})