Get Product
An easy way to get the product details directly from Shopify
Description
The getProduct helper retrieves detailed information about a specific Shopify product without making a direct API call. It provides the same data structure as the product variable on the PDP, including variants, options, images, and pricing information.
Function Signature
VajroSDK.helpers.getProduct({
productId: "8188148547769" //ID of the product from Shopify
})
.then((product) => console.log(product))
.catch((err) => console.log(error)
)
(OR)
VajroSDK.helpers.getProduct({
productHandle: "men-shirt" //Handle of the product from Shopify
})
.then((product) => console.log(product))
.catch((err) => console.log(error))
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | String | Yes (if handle is not passed) | Unique ID of the product form Shopify. |
| handle | String | Yes (if Id is not passed) | Handle of the product in Shopify Product URL. |
Structure of Response
| Property | Type | Description | Example |
|---|---|---|---|
| id | String | Unique ID of the product | "5678767788e" |
| title | String | Name of the product | Men shoes |
| description | String | HTML content of the product | "men shoes ..." |
| handle | String | Slug of the product used in URL | "men-shoes" |
| featuredImage | String | The main image associated to the product | "https://cdn.shopify.com/.../hoodie.jpg" |
| images | Array | Array of images associated to the product | [ "https://cdn.shopify.com/.../hoodie.jpg", "https://cdn.shopify.com/.../hoodie.jpg" ] |
| variants | Object[] | An object containing all the properties of the variant | [{"id": "1234","title":"grey"}] |
| options | Object[] | An object containing all option sets available for the product | [{"name": "Size","value":"XL"}] |
| vendor | String | Vendor name of the product | "CONVERSE" |
| requiresSellingPlan | boolean | Attribute related to subscription | true |
Usage Example
VajroSDK.helpers.getProduct({ productId: "8188148547769" })
.then((product) => {
document.getElementById("clc").innerHTML = JSON.stringify(product);
// Do the required functionality
})
.error((err) => {
document.getElementById("clc").innerHTML = "Error"
});Best Practices
- Use handle for readability: When possible, use the product handle (slug) for cleaner references.
- Cache results: For commonly used products (like upsells), store the result to avoid repeated calls.
- Error handling: Gracefully handle missing or unpublished products with fallback messaging.
Caveats
- Requires product context: The helper can only return products available in your Shopify store. Make sure it is made available for
- Data freshness: Cached data may delay a few seconds behind Shopify’s real-time updates.
- Limited metafields: Not all product metafields are returned by this helper.
- Null response: If the product is not found, the returned value will be null.
Updated 3 days ago