libraries/OutputBundle/EventListener/BMECatListener.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 BMECatListener
  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\BMECat) {
  19.                 // Do not autocreate any more! Use Command!
  20.                 return;
  21.                 if ($data->getCreatenow()) {
  22.                     // Set Customer (for Customer Price)
  23.                     $oldCustomItem false;
  24.                     if ($data->getKunde()) {
  25.                         $customer $data->getKunde();
  26.                         /* @var \Pimcore\Model\DataObject\Customer $customer */
  27.                         if (method_exists($customer"getCustomernumber")) {
  28.                             $kn $customer->getCustomernumber();
  29.                             if ($kn) {
  30.                                 $environment \Pimcore::getKernel()->getContainer()->get("pimcore_ecommerce.environment");
  31.                                 $oldCustomItem $environment->getCustomItem("ordercustomernumber");
  32.                                 $environment->setCustomItem("ordercustomernumber"$kn);
  33.                             }
  34.                         }
  35.                     }
  36.                     $translator \Pimcore::getKernel()->getContainer()->get("translator");
  37.                     $translator->setLocale($data->getSprache());
  38.                     $pimcoreLocale \Pimcore::getKernel()->getContainer()->get("pimcore.locale");
  39.                     $pimcoreLocale->setLocale($data->getSprache());
  40.                     $output = new \OutputBundle\OutputFormat\Xml();
  41.                     $output->setLanguage($data->getSprache());
  42.                     // remember option ETIM
  43.                     $output->customVariables["ETIM"] = $data->getETIM();
  44.                     $channel \OutputBundle\Service::getOutputDataConfig($data"bmecat");
  45.                     foreach ($channel as $property) {
  46.                         $output->createNode($property$datanull);
  47.                     }
  48.                     $dataExport $output->getXml();
  49.                     $exportFolder Asset::getByPath("/exports/bmecat");
  50.                     if ($exportFolder && $exportFolder->getId() > 0) {
  51.                         $parentId $exportFolder->getId();
  52.                         $asset Asset::getByPath("/exports/bmecat/{$data->getKey()}.xml");
  53.                         if ($asset) {
  54.                             $asset->delete();
  55.                         }
  56.                         Asset::create($parentId, ["filename" => $data->getKey() . ".xml",
  57.                             "type" => "application/xml",
  58.                             "data" => $dataExport]);
  59.                     }
  60.                     if ($oldCustomItem) {
  61.                         $environment->setCustomItem("ordercustomernumber"$oldCustomItem);
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.     }
  67. }