libraries/OutputBundle/EventListener/NRFListener.php line 21

Open in your IDE?
  1. <?php
  2. namespace OutputBundle\EventListener;
  3. use Pimcore\Event\Model\ElementEventInterface;
  4. use Pimcore\Event\Model\DataObjectEvent;
  5. use Pimcore\Model\Asset;
  6. use Pimcore\Model\DataObject\Folder;
  7. use Pimcore\Model\DataObject\Product;
  8. class NRFListener
  9. {
  10.     public function __construct()
  11.     {
  12.     }
  13.     public function onPostUpdate(ElementEventInterface $e)
  14.     {
  15.         if ($e instanceof DataObjectEvent) {
  16.             /* @var Product $data */
  17.             $data $e->getObject();
  18.             if ($data instanceof \Pimcore\Model\DataObject\NRFConfig) {
  19.                 if ($data->getCreatenow()) {
  20.                     $translator \Pimcore::getContainer()->get("translator");
  21.                     $translator->setLocale($data->getSprache());
  22.                     $pimcoreLocale \Pimcore::getContainer()->get("pimcore.locale");
  23.                     $pimcoreLocale->setLocale($data->getSprache());
  24.                     $output = new \OutputBundle\OutputFormat\AsCSV();
  25.                     $output->setLanguage($data->getSprache());
  26.                     if (method_exists($data"getDelimiter")) {
  27.                         $delimiter $data->getDelimiter();
  28.                         $output->setDelimiter($delimiter);
  29.                     }
  30.                     if (method_exists($data"getQuotes")) {
  31.                         $quotes $data->getQuotes();
  32.                         $output->setQuotes($quotes);
  33.                     }
  34.                     $channel \OutputBundle\Service::getOutputDataConfig($data"csv-nrf");
  35.                     foreach ($channel as $property) {
  36.                         $output->createNode($property$datanull);
  37.                     }
  38.                     $dataExport $output->get();
  39.                     $exportFolder Asset::getByPath("/exports/nrf");
  40.                     if ($exportFolder && $exportFolder->getId() > 0) {
  41.                         $parentId $exportFolder->getId();
  42.                         $asset Asset::getByPath("/exports/nrf/{$data->getKey()}.csv");
  43.                         if ($asset) {
  44.                             $asset->delete();
  45.                         }
  46.                         Asset::create($parentId, ["filename" => $data->getKey() . ".csv",
  47.                             "type" => "plain/text",
  48.                             "data" => $dataExport]);
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }