<?php declare(strict_types=1);
namespace Cbax\ModulManufacturers\Subscriber;
use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Framework\Context;
use Cbax\ModulManufacturers\Components\ManufacturersHelper;
class BackendSubscriber implements EventSubscriberInterface
{
/**
* @var ManufacturersHelper
*/
private $helperComponent;
public function __construct(ManufacturersHelper $helperComponent)
{
$this->helperComponent = $helperComponent;
}
public static function getSubscribedEvents(): array
{
return [
SystemConfigChangedEvent::class => 'onSystemConfigChanged'
];
}
//wenn Produktanzahl aus DB statt live Berechnung, runProductCount() ausführen, damit Daten immer vorhanden
public function onSystemConfigChanged(SystemConfigChangedEvent $event)
{
if ($event->getKey() === 'CbaxModulManufacturers.config.productCount' && $event->getValue() === 'notLive') {
$context = Context::createDefaultContext();
$this->helperComponent->runProductCount($context);
}
}
}