<?php declare(strict_types=1);
namespace Samson\Subscriber;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2020
*
***/
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Storefront\Page\Product\ProductPageCriteriaEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ProductSubscriber
* @package Samson\Subscriber
* @author Artur Seitz <artur.seitz@dkd.de>
*/
class ProductSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ProductPageCriteriaEvent::class => 'onProductPageCriteriaEvent'
];
}
public function onProductPageCriteriaEvent(ProductPageCriteriaEvent $event)
{
$criteria = $event->getCriteria();
$criteria->addAssociation('downloadLinks');
$criteria->getAssociation('downloadLinks')->addFilter(new EqualsFilter('languageId', $event->getSalesChannelContext()->getLanguageId()));
}
}