{% set page = hook.page %}
{# @var page \Shopware\Storefront\Page\Page #}

{% set criteria = {
    'aggregations': [
        { 'name': 'sumOfChildren', 'type': 'sum', 'field': 'childCount' }
    ]
} %}

{% set sumResult = services.store.aggregate('product', criteria).get('sumOfChildren') %}

{% do page.addArrayExtension('myProductAggregations', {
    'sum': sumResult.getSum
}) %}
