Skip to content

Category

The Category object represents a single product category in the storefront.

classDiagram
  direction LR
  Category --> Category
  Category --> CategoryUrl
  Category --> ProductsList
  ProductsList "1" --o "*" Product
  Category --> CategoriesList
  CategoriesList "1" --o "*" Category
  class Product{
  }
  class ProductsList{
  }
  class CategoriesList{
  }
  class CategoryUrl{
  }
  class Category{
    int id
    string name
    CategoryUrl url
    string description
    string additionalDescription
    bool isRoot
    bool isParent
    Category parentCategory
    CategoriesList subCategories
    ProductsList products
    ProductsList productsInSubTree
    Metafields metafields
  }

Properties

Attribute name Type Description
id int The unique identifier of the category.
name string The name of the category.
url CategoryUrl The CategoryUrl object that represents the url to the category.
description string The description of the category.
additionalDescription string The additional description of the category.
isRoot bool Return true if category has no parent.
isParent bool Return true if category has subcategories.
parentCategory Category Reference to the Category object that represents parent category.
subcategories CategoriesList Reference to the CategoriesList object that represents the list of child Category object associated with this category.
products ProductsList Reference to the ProductsList object that represents the list of Product objects associated directly with this category.
productsInSubTree ProductsList Reference to the ProductsList object that represents the list of Product objects associated with this category and all its subcategories.
metafields Metafields Reference to the Metafields object that provides access to the namespaced containers for key - value pairs of data.

Examples

id property

{{ category.id }}
1

name property

{{ category.name }}
example name

url property

{{ category.url }}
/example/url

description property

{{ category.description }}
example description

additionalDescription property

{{ category.additionalDescription }}
example additional description

isRoot property

{{ category.isRoot }}
true

isParent property

{{ category.isParent }}
true

parentCategory property

{{ category.parentCategory.name }}
example parent name

subCategories property

{% for subCategory in category.subCategories %}
    <p>{{ subCategory.name }}</p>
{% endfor %}
<p>subcategory name 1</p>
<p>subcategory name 2</p>
<p>subcategory name 3</p>

products property

{% for product in category.products %}
    <a href="{{ product.url }}" title="{{ product.name }}">
        {{ product.name }}
    </a>
{% endfor %}
<a href="/pl/p/product-in-category/11" title="Product in category">
    Product in category
</a>
<a href="/pl/p/product-in-category-2/12" title="Product in category 2">
    Product in category 2
</a>

productsInSubTree property

{% for product in category.productsInSubTree %}
    <a href="{{ product.url }}" title="{{ product.name }}">
        {{ product.name }}
    </a>
{% endfor %}
<a href="/pl/p/product-in-category/11" title="Product in category">
    Product in category
</a>
<a href="/pl/p/product-in-category-2/12" title="Product in category 2">
    Product in category 2
</a>
<a href="/pl/p/product-in-category-2/12" title="Product in category 2">
    Product in subcategory
</a>

metafields property

value: {{ category.metafields.someNamespaceName.key }}
value: example-value-3