<?php declare(strict_types=1);
namespace Swag\BasicExample\Service;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Metric\CountAggregation;
use Shopware\Core\Framework\DataAbstractionLayer\Search\AggregationResult\Metric\CountResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddDataToPage implements EventSubscriberInterface
private EntityRepositoryInterface $productRepository;
public function __construct(EntityRepositoryInterface $productRepository)
$this->productRepository = $productRepository;
public static function getSubscribedEvents(): array
FooterPageletLoadedEvent::class => 'addActiveProductCount'
public function addActiveProductCount(FooterPageletLoadedEvent $event): void
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('product.active', true));
$criteria->addAggregation(new CountAggregation('productCount', 'product.id'));
/** @var CountResult $productCountResult */
$productCountResult = $this->productRepository
->aggregate($criteria, $event->getContext())
$event->getPagelet()->addExtension('product_count', $productCountResult);