custom/plugins/TTExportProduct/src/Subscriber/ProductExportChangeEncodingSubscriber.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TTExportProduct\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Content\ProductExport\Event\ProductExportChangeEncodingEvent;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. class ProductExportChangeEncodingSubscriber implements EventSubscriberInterface
  7. {
  8.     const BASE_FILE_NAME 'billiger.csv';
  9.     private SystemConfigService $systemConfigService;
  10.     public function __construct(SystemConfigService $systemConfigService)
  11.     {
  12.         $this->systemConfigService $systemConfigService;
  13.     }
  14.     public static function getSubscribedEvents()
  15.     {
  16.         return [
  17.             ProductExportChangeEncodingEvent::class => 'onExportProductApi'
  18.         ];
  19.     }
  20.     /**
  21.      * @throws Exception
  22.      */
  23.     public function onExportProductApi(ProductExportChangeEncodingEvent $event): void
  24.     {
  25.         $fileNameHtmlDecode $this->systemConfigService->get('TTExportProduct.config.fileNameHtmlDecode');
  26.         if(empty($fileNameHtmlDecode)) {
  27.             $fileNameHtmlDecode self::BASE_FILE_NAME;
  28.         }
  29.         $productExportEntity $event->getProductExportEntity();
  30.         if(strpos($fileNameHtmlDecode$productExportEntity->getFileName()) !== false) {
  31.             $encodeContent $event->getEncodedContent();
  32.             $event->setEncodedContent(html_entity_decode($encodeContent));
  33.         }
  34.     }
  35. }