item_attributes

This component fetches all attributes/options for a specified product. By default, each attribute group is rendered, with its options and any prices, according to their specified form inputs.

{% component type: "item_attributes", module: "<Module name/ID>", itemId: "<Item Id>" %}

Parameters and Options

Parameter Values Required Description
type item_attributes

This is the name of the entity that needs to be used for the component retrieving function.

module <Module name/ID> The entity/alias name or ID that the data is to be sourced from.
itemId <Item ID> The module item ID (specific Product) the data is to be sourced from
layout <Your Layout name>
The layout name you want to use for rendering the component. The layout name is referenced from the available Layouts of the source specified. If the parameter is blank or has an incorrect referenced Layout then the component will not render any code.
object item
collection (default)

Determines the method for Liquid rendering.
item returns each item iteratively, one after another, for output (generally, output to a container element with no need for looping through the data).
collection returns all items as one collection for output (your container element and looping logic would be handled in the Components Layout).
collectionVariable <yourLiquidVariableName>
Assigns the data to a Liquid collection enabling further access to the data on the Page or Template using Liquid.

Your collectionVariable value must only contain English letters, numbers or underscores. Spaces or special characters are not supported.

Liquid Output

The below example shows the attributes available for the specified product ID. The Liquid data output from this example would look like the following (for example, when using a collectionVariable to create the collection):

{
  "items": {
  "eCommerceItemId": 2535,
  "attributes": [
    {
      "id": "12462596046050033665",
      "name": "Size",
      "attributeType": "dropdown",
      "valueType": "FixedPrice",
      "required": true,
      "addToInventory": true,
      "options": [
        {
          "id": "16234894512508370945",
          "name": "Small",
          "image": "/images/template-detail-crafter-mobile.png",
          "priceValue": 0.0000,
          "formattedPrice": "$0.00",
          "taxPrice": 0.0,
          "country": "US",
          "currency": {
            "code": "USD",
            "symbol": "$",
            "name": "US Dollar",
            "digitalCode": "840"
          },
          "Weight": 0
        },
        {
          "id": "16234894512508370946",
          "name": "Medium",
          "image": "/images/template-crafter@2x.jpg",
          "priceValue": 2.0000,
          "formattedPrice": "$2.00",
          "taxPrice": 0.0,
          "country": "US",
          "currency": {
            "code": "USD",
            "symbol": "$",
            "name": "US Dollar",
            "digitalCode": "840"
          },
          "Weight": 0
        },
        {
          "id": "16234894512508370947",
          "name": "Large",
          "image": "/images/template-detail-crafter-desktop@2x.jpg",
          "priceValue": 4.0000,
          "formattedPrice": "$4.00",
          "taxPrice": 0.0,
          "country": "US",
          "currency": {
            "code": "USD",
            "symbol": "$",
            "name": "US Dollar",
            "digitalCode": "840"
          },
          "Weight": 0
        }
      ],
      "weight": 0
    }
  ]
}
}

Virtual Layout

Based on the above example, if not using any custom layout or collection, the default virtual layout will output as form elements (depending on their attributeType):

Size


<form name="productAttributeForm_{{this.eCommerceItemId}}" data-ecommerce_item="{{this.eCommerceItemId}}">
    {% for attribute in this.attributes %}
        <h3 >{{attribute.name}}</h3>
        {% case attribute.attributeType %}
            {% when 'dropdown' %}
                <div class="cms_fake_select" data-attr_group="{{attribute.id}}">
                   <select name="attr_{{this.eCommerceItemId}}_{{attribute.id}}">
                       <option value="">Please select</option>
                    {% for attrOption in attribute.options %}
                        <option value="{{attrOption.id}}" {% if attrOption.image != '' and attrOption.image != null %} style="background-image:url({{attrOption.image}});"{% endif %}>{{attrOption.name}} {{attrOption.formattedPrice}}</option>
                    {% endfor %}
                </select>
            </div>
            {% when 'checkbox' %}
             <div data-attr_group="{{attribute.id}}">
            {% for attrOption in attribute.options %}
            <div class="cms_custom_input">
                <label>
                    <input type="checkbox" name="attr_{{this.eCommerceItemId}}_{{attribute.id}}" value="{{attrOption.id}}">
                    {% if attrOption.image != '' and attrOption.image != null %}
                        <img src="{{attrOption.image}}?width=40&height=40" width="40" height="40" title="{{attrOption.name}}" alt="{{attrOption.name}}">
                    {% else %}
                        <span class="cms_fake_input"></span>
                     {% endif %}
                    <span class="cms_fake_label">{{attrOption.name}} {{attrOption.formattedPrice}}</span>
                </label>
            </div>
            {% endfor %}
            </div>
            {% when 'radiolist' %}
            <div data-attr_group="{{attribute.id}}">
                {% for attrOption in attribute.options %}
                <div class="cms_custom_input">
                    <label>
                        <input type="radio" name="attr_{{this.eCommerceItemId}}_{{attribute.id}}" value="{{attrOption.id}}">
                        {% if attrOption.image != '' and attrOption.image != null %}
                            <img src="{{attrOption.image}}?width=40&height=40" width="40" height="40" title="{{attrOption.name}}" alt="{{attrOption.name}}">
                        {% else %}
                        <span class="cms_fake_input"></span>
                        {% endif %}
                        <span class="cms_fake_label">{{attrOption.name}} {{attrOption.formattedPrice}}</span>
                    </label>
                </div>
                {% endfor %}
                </div>
            {% when 'numeric' %}
                <div style="text-align: center" data-attr_group="{{attribute.id}}">{% for attrOption in attribute.options %}
                    <label>{{attrOption.name}} {{attrOption.formattedPrice}}</label>
                    {% if attrOption.image != '' and attrOption.image != null %}
                        <img src="{{attrOption.image}}?width=40&height=40" width="40" height="40" alt="{{attrOption.name}}">
                    {% endif %}
                    <input type="number" {% if attribute.required == true %} required{% endif %} name="attr_{{this.eCommerceItemId}}_{{attribute.id}}" value="">
                {% endfor %}</div>
            {% else %}
        {% endcase %}</br>
    {% endfor %}
</form>

Accessing the Data

This data is accessible directly on the Page or Template via a Liquid Collection if collectionVariable was added to the Component.

An example using collectionVariable with value "attrCollection":

{% component type: "item_attributes", module: "2485", itemId: "2535", collectionVariable: "attrCollection" %}

Using the following forloop directly on the page:

<ul>
    {% for attr in attrCollection.items.attributes %}
        <li>{{attr['name']}}</li>
    {% endfor %}
</ul>

Renders all the item names in a list:

  • Size

Accessing a specific item within the collection. In this case the third attributes option (zero based index), which in our example would render the value Large

{{attrCollection.items.attributes[0].options[2]['name']}}


Related Articles

  • Payment Settings
  • Orders
  • {{ order }} object
    This liquid object will output the order details of a submitted payment. {% capture data...
  • module (Catalogs)
    This module component fetches data relating to eCommerce Catalogs and can be used to render Catalog structures and Products within them.
  • module (Products)
    This module component fetches data relating to eCommerce Products and can be used to render Product information.
  • ecommerce_add_to_cart
    This component renders an anchor element allowing the javascript function to add the item to the shopping cart.
  • ecommerce_buy_now
    This component renders an anchor element allowing the javascript function to add the item to the shopping cart and then proceeding directly to the shopping cart page.
  • ecommerce_item_quantity
    This component renders a form input element allowing a quantity to be set for when the source item is added to the shopping cart.
  • related_items
    This component fetches related items of a specific source item, such as a Product that has had Related Products assign to it.
  • grouped_items
    This component fetches grouped items of a specific source item, such as a Product that has been Grouped with other Products and allows the ability to navigate between grouped items.
  • currencies
    This component renders a form select element of all currency names, codes and symbols by default, and can also be used to output currency data to a Liquid collection.
  • shopping_cart
    This component fetches data relating to the shopping cart, such as any products added, order totals, tax, shipping, etc.
  • shipping_options
    This component renders a form select element of all shipping options configured on the site, and can also be used to output shipping option data to a Liquid collection.
  • tax_codes
    This component renders a form select element of all tax codes configured on the site, and can also be used to output tax code data to a Liquid collection.
  • payment_form_fields
    This component is used to render payment fields, and payment related validation errors, within a form using the capabilities provided by your configured payment gateway.
  • orders
    This component fetches Orders from the CRM, either owned by the logged-in user or for all customer Orders.
  • Getting Started
    With the recent release of eCommerce features there are some advanced system components that are...
  • Products
    Products are one of the most powerful and flexible modules in Treepl CMS. Create customised product schemas with multiple price points, catalogs, inventory tracked attributes/variables, SEO optimisation and more.
  • Catalogs
    When organising any eCommerce store, Catalogs are crucial to your Products structure and browserbility. Easily create and customise unlimited product catalogs for your online store.
  • countries
    This component renders a form select element of all country names and country codes by default, and can also be used to output country codes/names to a Liquid collection.
  • domain_settings
    This module component retrieves settings associated with the current domain, or optionally from another specified domain configured in the site instance.

External Resources

There are currently no external resources available.

Please let us know if you have any other contributions or know of any helpful resources you'd like to see added here.


Questions?

We are always happy to help with any questions you may have.
Send us a message at support@treepl.co and we will consult you as soon as possible.