custom/plugins/PickwareErpStarter/src/ImportExport/ModelSubscriber/IsDownloadReadyFieldCalculationSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\PickwareErpStarter\ImportExport\ModelSubscriber;
  11. use Pickware\PickwareErpStarter\ImportExport\Model\ImportExportDefinition;
  12. use Pickware\PickwareErpStarter\ImportExport\Model\ImportExportEntity;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class IsDownloadReadyFieldCalculationSubscriber implements EventSubscriberInterface
  16. {
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             ImportExportDefinition::EVENT_LOADED => 'onImportExportLoaded',
  21.         ];
  22.     }
  23.     public function onImportExportLoaded(EntityLoadedEvent $event): void
  24.     {
  25.         /** @var ImportExportEntity $importExport */
  26.         foreach ($event->getEntities() as $importExport) {
  27.             $importExport->assign([
  28.                 'isDownloadReady' => false,
  29.             ]);
  30.             if (!$importExport->getDocumentId()) {
  31.                 continue;
  32.             }
  33.             if ($importExport->getType() === ImportExportDefinition::TYPE_IMPORT || (
  34.                     $importExport->getType() === ImportExportDefinition::TYPE_EXPORT
  35.                     && $importExport->getState() === ImportExportDefinition::STATE_COMPLETED
  36.                 )) {
  37.                 $importExport->assign([
  38.                     'isDownloadReady' => true,
  39.                 ]);
  40.             }
  41.         }
  42.     }
  43. }