Product
An easy way to access and use Shopify Product data within the Superfans SDK.
Description
The product variable provides details about the collection on a Product Detail (PDP) page. It includes the collection’s ID, title, handle, description, and main image. The collection object is only available on PDP pages; outside of a PDP context, it is null.
Properties of Product
Property | Type | Scope | Description | Example |
|---|---|---|---|---|
|
|
| Unique id of the product | 2837648235648 |
|
|
| Indicates if the product is available for purchase. | true |
|
|
| Price to display as markdown, which is higher than actual price | 12.99 |
|
|
| The textual description of the product in Shopify | Beach Shirt |
|
|
| User-friendly slug used in Shopify product URL. | beach-shirt |
|
|
| Array of images for the Product | |
|
|
| The actual price of the product | 10.99 |
|
|
| Array of Shopify tags attached to the product. | ["beach","new","flash_sale"] |
|
|
| Name of the product | Beach Shirt |
|
|
| The URL of the product | |
|
|
| Name of the vendor or brand. | Vajro |
|
|
| Currently selected variant of the product | JSON containing all the details of the variant |
|
|
| ID of the selected selling plan (if using subscriptions). | 1234234342 |
|
|
| Array of option definitions (e.g. size, color). Each entry has |
|
|
|
| Custom key‑value pairs defined on the product. |
|
Properties of variants
| Property | Type | Scope | Description | Example |
|---|---|---|---|---|
product.variants.id | String | PDP | Unique ID of the product variant | 871625368253 |
product.variants.title | Boolean | PDP | Given name of the product variant | Palm Blue |
product.variants.image | Boolean | PDP | Array of image URLs of the variant | [ "https://sample.vajro.com/image.jpg " ] |
product.variants.isAvailable | Boolean | PDP | Availability of the variant | true |
product.variants.price | Boolean | PDP | The actual price of the product variant | 10.99 |
product.variants.compareAtPrice | Boolean | PDP | Price of the variant to display as markdown, which is higher than actual price | 13.99 |
product.variants.selectedOptions | Object[] | PDP | List of option name/value pairs selected for this variant. | [ { name: "Color", value: "Black" } ] |
product.variants.sku | String | PDP | Stock Keeping Unit of the Product variant | 12344145 |
product.variants.sellingPlanAccocations | Object | PDP | Selling plan allocations for the variant (if applicable). |
Usage Example
const product_data = VajroSDK.variables.product;
if (product_data) {
// Display basic product info
console.log(`Product: ${product.title} — ${product.price}`);
// Show options (e.g. color, size)
product.options?.forEach((opt) => {
console.log(`Option: ${opt.name} = ${opt.value}`);
});
// Access the selected variant
const selected_variant = product.selectedVariant;
if (selected_variant) {
console.log(`Selected variant SKU: ${variant.sku}`);
console.log(`Variant price: ${variant.price}`);
}
} else {
// The product object is only available on PDPs
console.log("Not on a product page.");
}Best Practices
- PDP only: The product variable is defined only on product detail pages; always check for null when using it elsewhere.
- Listen for variant changes: Use the Variant Change listener to update UI elements (price, images, inventory) when a user selects a different variant.
- Use selectedVariant for accuracy: Display price, availability and SKU based on product.selectedVariant rather than the first variant by default.
- Handle optional fields gracefully: Fields like compareAtPrice, tags, metafields and sellingPlanId may be absent; guard against undefined values.
- Read‑only data: Do not attempt to modify properties of the product or its variants; they reflect Shopify data and cannot be edited from the client side.
Caveats
- Scope limited to PDP: The product variable returns null on any page that is not a product detail page
- Incomplete or missing fields: Not all products have tags, compare‑at prices, metafields or images; always check for existence before using these fields.
- Variant data types: Variant properties such as title, image, price, and compareAtPrice are strings/floats, not Booleans, even though the original table lists them incorrectly. Adjust your code accordingly.
- Selected variant availability: The selectedVariant may be null until a user selects an option; handle this case when displaying variant‑dependent information.
Updated about 1 month ago