Product lookup

Use the shared storefront runtime to read public Measura product and variant configuration from theme code.

Availability

These shared storefront methods are available as long as the Measura shared runtime is loaded.

  • They do not require a mounted Measura product block.
  • They return public Measura product configuration for storefront integrations.
  • They do not return raw window.AtomicPOS runtime state.

Lookup behavior

Both methods can find product state by productId or productHandle.

  • If productId is provided and the product is already registered in window.AtomicPOS.products, Measura uses that product directly.
  • If only productHandle is provided, Measura searches already registered products by exact handle match.
  • If the product is not already registered and productHandle is provided, Measura fetches the product page, replays the embedded Measura block script in hydrate-only mode, resolves the Shopify product id from that script, and returns the hydrated product config.

Sanitized responses

  • productId is optional when productHandle is provided.
  • productHandle is required for cold hydration because Measura uses it to fetch the product page.
  • Returned objects are sanitized clones, not direct references to window.AtomicPOS.products.
  • Mutating returned objects does not mutate Measura runtime state.
  • Internal runtime fields such as DOM targets, listener callbacks, raw metafield objects, and debug fields are not returned.

Method summary

MethodAsyncDescription
getProduct(options)YesReturn public Measura configuration for a measured product.
getVariant(options)YesReturn public Measura configuration for one measured variant.

window.Measura.getProduct(options)

Returns the public Measura configuration for a measured product.

Input

{
  productId?: string | number;
  productHandle?: string;
}

Output

Promise<{
  id: string;
  handle?: string;
  measurementType?: "weight" | "length" | "area" | "volume" | "time";
  selectedVariantId?: string;
  variants: Record<
    string,
    {
      id: string;
      title?: string;
      price?: number;
      compareAtPrice?: number;
      formattedPrice?: string;
      formattedCompareAtPrice?: string;
      rawFormattedPrice?: string;
      rawFormattedCompareAtPrice?: string;
      isPricingRulePrice?: true;
      unitMeasurement?: {
        value?: number;
        unit?: string;
      };
      purchaseCondition?: {
        min?: number;
        max?: number;
        increment?: number;
      } & Record<string, any>;
      settings?: {
        displayStyle?: string;
        presets?: Array<Record<string, any>>;
      };
      inventory?: {
        tracksInventory: boolean;
        quantity?: number;
        continueSellingWhenOutOfStock: boolean;
      };
    }
  >;
} | null>

Return fields

FieldDescription
idShopify product id as a string.
handleShopify product handle when available.
measurementTypeMeasura measurement type configured for the product.
selectedVariantIdSelected or first available variant id from the product block bootstrap.
variantsObject keyed by Shopify variant id.
variants[variantId].priceVariant price in minor units, such as cents.
variants[variantId].compareAtPriceCompare-at price in minor units when available.
variants[variantId].formattedPriceLiquid-formatted price string.
variants[variantId].unitMeasurementUnit measurement used for unit-price calculations.
variants[variantId].purchaseConditionMinimum, maximum, increment, and related purchase rules.
variants[variantId].settings.displayStyleCurrent Measura input style for the variant, such as pills or dropdown.
variants[variantId].settings.presetsConfigured preset values and labels when available.
variants[variantId].inventoryPublic inventory flags and quantity when Liquid exposed inventory data.

Returns null when

  • The product cannot be found or hydrated.
  • The fetched product page does not contain a Measura block script.
  • The product is not configured as a Measura product.

Throws when

  • Both productId and productHandle are missing.
  • Product hydration is needed but productHandle is missing.
  • The product page fetch fails.
  • The browser environment cannot hydrate product state.
  • Product hydration times out.

Example

const product = await window.Measura.getProduct({
  productHandle: "sample-backpack-4"
});

if (product) {
  console.log(product.measurementType);
  console.log(product.variants[product.selectedVariantId]);
}

Example response:

{
  "id": "9904458072362",
  "handle": "sample-backpack-4",
  "measurementType": "weight",
  "selectedVariantId": "50661130010922",
  "variants": {
    "50661130010922": {
      "id": "50661130010922",
      "title": "Default Title",
      "price": 1200,
      "formattedPrice": "$12.00",
      "unitMeasurement": {
        "value": 1,
        "unit": "lb"
      },
      "purchaseCondition": {
        "min": 0.25,
        "increment": 0.25
      },
      "settings": {
        "displayStyle": "pills",
        "presets": [
          {
            "label": "1 lb",
            "value": 1
          }
        ]
      },
      "inventory": {
        "tracksInventory": true,
        "quantity": 8,
        "continueSellingWhenOutOfStock": false
      }
    }
  }
}

window.Measura.getVariant(options)

Returns the public Measura configuration for one measured variant. This is a convenience wrapper over the same product lookup and hydration path used by getProduct().

Input

{
  productId?: string | number;
  productHandle?: string;
  variantId: string | number;
}

Output

Promise<{
  id: string;
  title?: string;
  price?: number;
  compareAtPrice?: number;
  formattedPrice?: string;
  formattedCompareAtPrice?: string;
  rawFormattedPrice?: string;
  rawFormattedCompareAtPrice?: string;
  isPricingRulePrice?: true;
  unitMeasurement?: {
    value?: number;
    unit?: string;
  };
  purchaseCondition?: {
    min?: number;
    max?: number;
    increment?: number;
  } & Record<string, any>;
  settings?: {
    displayStyle?: string;
    presets?: Array<Record<string, any>>;
  };
  inventory?: {
    tracksInventory: boolean;
    quantity?: number;
    continueSellingWhenOutOfStock: boolean;
  };
} | null>

Returns null when

  • The product cannot be found or hydrated.
  • The product is not configured as a Measura product.
  • The requested variant is not present in the hydrated Measura config.

Throws when

  • Both productId and productHandle are missing.
  • variantId is missing.
  • Product hydration is needed but productHandle is missing.
  • The product page fetch fails.
  • The browser environment cannot hydrate product state.
  • Product hydration times out.

Example

const variant = await window.Measura.getVariant({
  productHandle: "sample-backpack-4",
  variantId: 50661130010922
});

if (variant?.settings?.presets) {
  renderPresetButtons(variant.settings.presets);
}

Example response:

{
  "id": "50661130010922",
  "title": "Default Title",
  "price": 1200,
  "formattedPrice": "$12.00",
  "unitMeasurement": {
    "value": 1,
    "unit": "lb"
  },
  "purchaseCondition": {
    "min": 0.25,
    "increment": 0.25
  },
  "settings": {
    "displayStyle": "pills",
    "presets": [
      {
        "label": "1 lb",
        "value": 1
      }
    ]
  },
  "inventory": {
    "tracksInventory": true,
    "quantity": 8,
    "continueSellingWhenOutOfStock": false
  }
}