<?php declare(strict_types=1);
namespace TTExportProduct\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\ProductExport\Event\ProductExportChangeEncodingEvent;
use Shopware\Core\System\SystemConfig\SystemConfigService;
class ProductExportChangeEncodingSubscriber implements EventSubscriberInterface
{
const BASE_FILE_NAME = 'billiger.csv';
private SystemConfigService $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents()
{
return [
ProductExportChangeEncodingEvent::class => 'onExportProductApi'
];
}
/**
* @throws Exception
*/
public function onExportProductApi(ProductExportChangeEncodingEvent $event): void
{
$fileNameHtmlDecode = $this->systemConfigService->get('TTExportProduct.config.fileNameHtmlDecode');
if(empty($fileNameHtmlDecode)) {
$fileNameHtmlDecode = self::BASE_FILE_NAME;
}
$productExportEntity = $event->getProductExportEntity();
if(strpos($fileNameHtmlDecode, $productExportEntity->getFileName()) !== false) {
$encodeContent = $event->getEncodedContent();
$event->setEncodedContent(html_entity_decode($encodeContent));
}
}
}