---
title: "variant"

doc_type: static
doc_category: static
doc_version: v20260901
source_url:
  html: 'https://developer.shopline.com/docs/handlebars/objects/variant'
  md: 'https://developer.shopline.com/docs/handlebars/objects/variant.md'
---


# variant

<div className="code-flex">

<div>
  <ObjectSummary>
    A [product variant](https://help.shopline.com/hc/en/articles/16246202519065-%E7%AE%A1%E7%90%86%E5%95%86%E5%93%81%E5%A4%9A%E5%B1%9E%E6%80%A7).
  </ObjectSummary>

  #### Properties

  <ObjectProperty
    name="available"
    types={["boolean"]}
  >
    <ObjectSummary>
      Returns `true` if the variant is available. Returns `false` if not.
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="barcode"
    types={["string"]}
  >
    <ObjectSummary>
      The barcode of the variant.
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="compare_at_price"
    types={["number"]}
  >
    <ObjectSummary>
      The **compare at** price of the variant in the currency's subunit.

      The value is output in the customer's local (presentment) currency.

  > **Tip**
>
> Use [money helpers](https://developer.shopline.com/docs/handlebars/helpers/money/money.md) to output a formatted price.
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="featured_image"
    types={["image"]}
  >
    <ObjectSummary>
      The image attached to the variant.
  > **Note**
>
> This is the same value as [variant.image](#image).
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="featured_media"
    types={["media"]}
  >
    <ObjectSummary>
      The first media object attached to the variant.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="id"
    types={["string"]}
  >
    <ObjectSummary>
      The ID of the variant.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="image"
    types={["image"]}
  >
    <ObjectSummary>
      The image attached to the variant.
  > **Note**
>
> This is the same value as [variant.featured_image](#featured_image).
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="inventory_quantity"
    types={["number"]}
  >
    <ObjectSummary>
      The inventory quantity of the variant.

      If inventory isn't tracked, then `0` is returned.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="metafields"
  >
  {/* TODO 补充链接 */}
    <ObjectSummary>
      The [metafields](https://developer.shopline.com/docs/handlebars/objects/metafield.md) applied to the variant.
  > **Tip**
>
> To learn about how to create metafields, refer to Create and manage metafields or visit the [Shopline Help Center](https://help.shopline.com/hc/en/articles/7095355017113-%E5%85%83%E5%AD%97%E6%AE%B5-Metafields-%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97).
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="option1"
    types={["string"]}
  >
    <ObjectSummary>
      The value of the variant for the first product option.

      If there's no first product option, then `null` is returned.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="option2"
    types={["string"]}
  >
    <ObjectSummary>
      The value of the variant for the second product option.

      If there's no second product option, then `null` is returned.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="option3"
    types={["string"]}
  >
    <ObjectSummary>
      The value of the variant for the third product option.

      If there's no third product option, then `null` is returned.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="option4"
    types={["string"]}
  >
    <ObjectSummary>
      The value of the variant for the fourth product option.

      If there's no fourth product option, then `null` is returned.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="option5"
    types={["string"]}
  >
    <ObjectSummary>
      The value of the variant for the fifth product option.

      If there's no fifth product option, then `null` is returned.
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="options"
    types={["string"]}
  >
    <ObjectSummary>
      The values of the variant for each [product option](https://developer.shopline.com/docs/handlebars/objects/product-option.md).
    </ObjectSummary>

    <Example data={['product.variants.{id,options}']} layout="vertical">
      ```handlebars
      {{#each product.variants as |variant|}}
        {{variant.id}}: {{join variant.options '/'}}
      {{/each}}
      ```
    </Example>
  </ObjectProperty>
  <ObjectProperty
    name="price"
    types={["number"]}
  >
    <ObjectSummary>
      The price of the variant in the currency's subunit.

      The value is output in the customer's local (presentment) currency.
  > **Tip**
>
> Use [money helpers](https://developer.shopline.com/docs/handlebars/helpers/money/money.md) to output a formatted price.
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="requires_selling_plan"
    types={["boolean"]}
  >
    <ObjectSummary>
      Returns `true` if the variant is set to require a selling_plan when being added to the cart. Returns `false` if not.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="requires_shipping"
    types={["boolean"]}
  >
    <ObjectSummary>
      Returns `true` if the variant requires shipping. Returns `false` if it doesn't.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="selected"
    types={["boolean"]}
  >
    <ObjectSummary>
      Returns `true` if the variant is currently selected. Returns `false` if it's not.
  > **Note**
>
> The selected variant is determined by the `variant` URL parameter. This URL parameter is available on product pages URLs only.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="selling_plan_allocation"
    types={["array of selling_plan_allocation"]}
  >
    <ObjectSummary>
      The `selling_plan_allocation` objects for the variant.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="sku"
    types={["string"]}
  >
    <ObjectSummary>
      The SKU of the variant.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="store_availabilities"
    types={["array of store_availability"]}
  >
    <ObjectSummary>
      The store availabilities for the variant.

      The array is defined in only the following cases:
      - `variant.selected` is `true`
      - The variant is the product's first available variant. For example, `product.first_available_variant` or `product.selected_or_first_available_variant`.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="taxable"
    types={["boolean"]}
  >
    <ObjectSummary>
      Returns `true` if taxes should be charged on the variant. Returns `false` if not.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="title"
    types={["string"]}
  >
    <ObjectSummary>
      A concatenation of each variant option, separated by a `/`.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="url"
    types={["string"]}
  >
    <ObjectSummary>
      The URL of the variant.

      Variant URLs use the following structure:

      /products/[product-handle]?sku=[variant-id]
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="weight_in_unit"
    types={["number"]}
  >
    <ObjectSummary>
      The weight of the variant in the unit specified by `variant.weight_unit`.
  > **Tip**
>
> To output this weight, use this property, and the `variant.weight_unit` property, with the weight_with_unit helper.
    </ObjectSummary>
  </ObjectProperty>
  <ObjectProperty
    name="weight_unit"
    types={["string"]}
  >
    <ObjectSummary>
      The unit for the weight of the variant.
  > **Tip**
>
> To output the weight of a variant in this unit, use this property, and the `variant.weight_in_unit` property, with the weight_with_unit helper.
    </ObjectSummary>
  </ObjectProperty>
</div>

<div>
  <ObjectAccess
    object="variant"
    global={false}
    parents={[
      { object: 'line_item.variant', link: '/docsv2/ec20/hdwvcvrgnfcjf4gq/9y14nnr3jpdahd7s#variant' },
      { object: 'product.first_available_variant', link: '/docsv2/ec20/hdwvcvrgnfcjf4gq/tfzgv1cp3z3wzk1s#first_available_variant' },
      { object: 'product.selected_or_first_available_variant', link: '/docsv2/ec20/hdwvcvrgnfcjf4gq/tfzgv1cp3z3wzk1s#selected_or_first_available_variant' },
      { object: 'product.variants', link: '/docsv2/ec20/hdwvcvrgnfcjf4gq/tfzgv1cp3z3wzk1s#variants' },
      { object: 'product.selected_variant', link: '/docsv2/ec20/hdwvcvrgnfcjf4gq/tfzgv1cp3z3wzk1s#selected_variant' },
      { object: 'variant', link: '/docsv2/ec20/hdwvcvrgnfcjf4gq/gjjjhvusthxd5ucy' },
    ]}
  />
</div>

</div>

