Get Products

An easy way to get multiple products details directly from Shopify

Description

The getProducts helper retrieves multiple Shopify products in a single call, based on collection ID or collection handle.
It provides a paginated list of products with core information — useful for PLPs, carousels, and recommendation blocks.

Function Signature

const data = await Superfans.helpers.getProducts({
  collectionHandle: "men",
  count: 10
});

const products = data.products || data;

(OR)

const data = await Superfans.helpers.getProducts({
  collectionId: "12346789",
  count: 10
});

const products = data.products || data;

We don't support metafields, market based filters and inventory based on location

ParameterTypeRequiredDescription
idStringYes (if handle is not passed)ID of the collection available in Shopify
handleStringYes (if id is not passed)Handle of the collection available in Shopify
countNumberYesNumber of products you want to fetch from the collection

Structure of Response

An array of products with each product having its properties.

Sample response structure of each product is mentioned below

PropertyTypeDescriptionExample
idStringUnique ID of each productproduct_id
titleStringName of each productProduct title
descriptionStringHTML content of each productProduct description
handleStringSlug of each product used in URLproduct-handle
featuredImageStringThe main image associated to each producthttps://cdn.shopify.com/image.jpg
imagesArrayArray of images associated to each product["https://cdn.shopify.com/image.jpg"]
variantsObject[]An object containing all the properties of the variant of each product[{"id": "1234","title":"grey"}]
selectedOptionsObject[]An object containing all option sets available for each product[{"name": "Size","value":"xl"}]
vendorStringVendor name of each productVendor

Example Usage

async function fetchProductsFromCollection(collectionId) {
  try {
    const data = await Superfans.helpers.getProducts({
      collectionId: collectionId,
      count: 10
    });
    const products = data.products || data;
    displayProducts(products);
  } catch (error) {
    await Superfans.actions.showToast({
      title: "Something went wrong",
      message: "Please try again."
    });
  }
}

function displayProducts(products) {
  const productGrid = document.getElementById("productGrid");
  productGrid.innerHTML = "";

  products.forEach((product) => {
    const card = document.createElement("div");
    card.className = "product-card";
    card.innerHTML = `
      <img src="${product.images[0]}" alt="${product.title}" class="product-image" />
      <div class="product-info">
        <div class="product-name">${product.title}</div>
      </div>
    `;
    productGrid.appendChild(card);
  });
}

fetchProductsFromCollection("123456789");

Best Practices

  1. Avoid overfetching: Always limit product count to optimize performance.
  2. Use consistent display logic: Match product card design to PDP for consistent UX.
  3. Graceful fallback: If no products are returned, display a “No items found” message.

Caveats

  1. Partial data: Product metafields and deep relationships are not included for performance reasons.
  2. Read-only: The helper retrieves products; it does not support modifications.
  3. Null safety: Always check if response.products is defined before accessing it.

Did this page help you?