src/C2IntegrationBundle/EventSubscriber/C2UserEventListener.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\C2IntegrationBundle\EventSubscriber;
  3. use Carbon\Carbon;
  4. use Pimcore\Model\DataObject\Customer;
  5. use Pimcore\Event\Model\DataObjectEvent;
  6. use App\C2IntegrationBundle\Service\C2Service;
  7. class C2UserEventListener
  8. {
  9.     private $c2Service;
  10.     public function __construct()
  11.     {
  12.         $this->c2Service = new C2Service();
  13.     }
  14.     public function onObjectCreate(DataObjectEvent $userObject)
  15.     {
  16.         $user $userObject->getObject();
  17.         if (($user instanceof Customer)) {
  18.             $userName $user->getName() ? $user->getName() : ' ';
  19.             $userEmail $user->getEmail();
  20.             $companyName $user->getOrganization() ? $user->getOrganization()->getName('en') : "";
  21.             $response $this->c2Service->generateContact($userName$userEmail$companyName);
  22.             if ($response) {
  23.                 if ($user->getCrmId()) {
  24.                     if ($response != $user->getCrmId()) {
  25.                         $user->setCrmId($response);
  26.                         $user->save();
  27.                     }
  28.                 } else {
  29.                     $user->setCrmId($response);
  30.                     $user->save();
  31.                 }
  32.             }
  33.             //$user->save();
  34.         }
  35.     }
  36. }