Skip to content

Object Api

Object Api is a collection of methods that allow you to gain access to the data in the store.

{% set product = ObjectApi.getProduct(product_id) %}

Objects

Objects contain properties to output dynamic content on the page. For example, the produt object contains a property called name that you can use to output the name of the product.

Properties of an object can be accessed using the . operator. For example, the following code outputs the name of the product:

{{ product.name }}

Properties of an object can also be a reference to another object.

{{ product.unit.name }}

If an object has a property referencing another object, that property can sometimes have a null value, even when it seems it shouldn't. This happens when some data is deleted during API object generation.

<h2>{{ product.name }}</h2>
{% for comment in product.comments %}
    <h2>{{ comment.product.name }}</h2>
{% endfor %}

output
<h2>Product name</h2>
<h2></h2>
<h2></h2>

Lists of objects

Some properties are not just strings, but also objects. For example, the product object contains a property called images that is a list of objects. It is possible to iterate over the list of images using the for loop:

{% for image in product.images %}
    {{ image.url }}
{% endfor %}

Every list is paginated. You can get the current page number by accessing the page property of the list:

{{ product.images.page }}

You can switch iterator to the next page by accessing the nextPage property or calling the nextPage() method of the list:

{{ product.images.page }}
{{ product.images.nextPage() }}
{{ product.images.page }}

You can switch iterator to the previous page by accessing the prevPage property or calling the prevPage() method of the list:

{{ product.images.page }}
{{ product.images.prevPage() }}
{{ product.images.page }}

You cen set the page number by calling the setPage() method and setting the value:

{{ product.images.page }}
{{ product.images.setPage(2) }}
{{ product.images.page }}

You can get the total number of pages by accessing the pages property of the list:

{{ product.images.pages }}

You can get the total number of items by accessing the count property of the list:

{{ product.images.count }}

You cen get current number of items per pages by accessing the itemCountPerPage property of the list:

{{ product.images.itemCountPerPage }}

You can change the number of items per page by calling the setItemCountPerPage() method of the list:

{{ product.images.setItemCountPerPage(10) }}

Available methods

Objects reference

Value objects

There are objects that are not specific to a product or a category or any other type of object. For example the product.createdAt property returns the DateTime object that represents the date and time when the product was created. This object itself is not product specific and is used in many types of objects. Value objects simplifies and standardizes access to common properties for developers.

Objects

Lists

Sometimes an Object Api method or a property of an object returns a list of objects. Those lists are paginated by default and can be iterated using the for loop.