Skip to content

Commerce Foundations is our pre-built Craft Commerce store. See what it includes

Craft CMS plugins

Variant Manager

A Craft CMS plugin that imports and exports Craft Commerce product variants from CSV files.

Template Tags

Available Functions#

The following functions are available:

craft.variantManager.getAttributeOptions(product, attributes)#

Accepts either a product ID or a Product, and an optional attribute filter to return options for specific attributes only.

Returns an array of associative arrays holding an attribute name and an array of possible values for that option.

{% set attributeOptions = craft.variantManager.getAttributeOptions(product.id) %}
{{ attributeOptions | json_encode }}

Would output something similar to:

[
  {
    "name": "Option A",
    "values": [
      "Value 1",
      "Value 2",
      "Value 3"
    ]
  },
  {
    "name": "Option B",
    "values": [
      "Value 1"
    ]
  },
  {
    "name": "Option C",
    "values": [
      "Value 1",
      "Value 2",
      "Value 3",
      "Value 4"
    ]
  }
]

Example: Get all attribute options#

{% set product = craft.products().id(30) %}

<div>
  {% set attributeOptions = craft.variantManager.getAttributeOptions(product.id) %}
  {% for item in attributeOptions %}
    {% set itemIndex = loop.index %}
    <h2>{{ item.name }}</h2>
    {% for value in item.values %}
      <label>
        <input type="radio" name="{{ itemIndex }}_option" value="{{ value }}"/>
        <span>{{ value }}</span>
      </label>
    {% endfor %}
  {% endfor %}
</div>

Example: Get a specific attribute’s options#

{% set product = craft.products().id(30) %}

<div>
  {% set attributeOptions = craft.variantManager.getAttributeOptions(product.id, "Option A") %}
  {% for item in attributeOptions %}
    {% set itemIndex = loop.index %}
    <h2>{{ item.name }}</h2>
    {% for value in item.values %}
      <label>
        <input type="radio" name="{{ itemIndex }}_option" value="{{ value }}"/>
        <span>{{ value }}</span>
      </label>
    {% endfor %}
  {% endfor %}
</div>

We can take it from here.

We take on the Craft and Craft Commerce sites you built, so you can get back to building. Introduce a client who signs a management contract and you get a $3,000 partnership fee.

How the Dev Partnership Program works
See if we’re a fit