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

product.id

String

PDP

Unique id of the product

2837648235648

product.availableForSale

Boolean

PDP

Indicates if the product is available for purchase.

true

product.compareAtPrice

Float

PDP

Price to display as markdown, which is higher than actual price

12.99

product.description

String

PDP

The textual description of the product in Shopify

Beach Shirt

product.handle

String

PDP

User-friendly slug used in Shopify product URL.

beach-shirt

product.images

String[]

PDP

Array of images for the Product

[ "https://sample.vajro.com/image.jpg" ]

product.price

Float

PDP

The actual price of the product

10.99

product.tags

String[]

PDP

Array of Shopify tags attached to the product.

["beach","new","flash_sale"]

product.title

String

PDP

Name of the product

Beach Shirt

product.url

String

PDP

The URL of the product

https://www.vajro.com/products/shirt

product.vendor

String

PDP

Name of the vendor or brand.

Vajro

product.selectedVariant

Object

PDP

Currently selected variant of the product

JSON containing all the details of the variant
[ { id: 1234, title: "Black" } ]

product.sellingPlanId

String

PDP

ID of the selected selling plan (if using subscriptions).

1234234342

product.options

Object[]

PDP

Array of option definitions (e.g. size, color). Each entry has name and value.

[ { name: "Color", value: "Black" } ]

product.metafields

Object[]

PDP

Custom key‑value pairs defined on the product.

[ { key: "material", : value: "Black" } ]

Properties of variants

PropertyTypeScopeDescriptionExample
product.variants.idStringPDPUnique ID of the product variant871625368253
product.variants.titleBooleanPDPGiven name of the product variantPalm Blue
product.variants.imageBooleanPDPArray of image URLs of the variant[ "https://sample.vajro.com/image.jpg " ]
product.variants.isAvailableBooleanPDPAvailability of the varianttrue
product.variants.priceBooleanPDPThe actual price of the product variant10.99
product.variants.compareAtPriceBooleanPDPPrice of the variant to display as markdown, which is higher than actual price13.99
product.variants.selectedOptionsObject[]PDPList of option name/value pairs selected for this variant.[ { name: "Color", value: "Black" } ]
product.variants.skuStringPDPStock Keeping Unit of the Product variant12344145
product.variants.sellingPlanAccocationsObjectPDPSelling 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

  1. PDP only: The product variable is defined only on product detail pages; always check for null when using it elsewhere.
  2. Listen for variant changes: Use the Variant Change listener to update UI elements (price, images, inventory) when a user selects a different variant.
  3. Use selectedVariant for accuracy: Display price, availability and SKU based on product.selectedVariant rather than the first variant by default.
  4. Handle optional fields gracefully: Fields like compareAtPrice, tags, metafields and sellingPlanId may be absent; guard against undefined values.
  5. 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

  1. Scope limited to PDP: The product variable returns null on any page that is not a product detail page
  2. Incomplete or missing fields: Not all products have tags, compare‑at prices, metafields or images; always check for existence before using these fields.
  3. 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.
  4. Selected variant availability: The selectedVariant may be null until a user selects an option; handle this case when displaying variant‑dependent information.