<?php
namespace App\C2IntegrationBundle\EventSubscriber;
use Carbon\Carbon;
use Pimcore\Model\DataObject\Customer;
use Pimcore\Event\Model\DataObjectEvent;
use App\C2IntegrationBundle\Service\C2Service;
class C2UserEventListener
{
private $c2Service;
public function __construct()
{
$this->c2Service = new C2Service();
}
public function onObjectCreate(DataObjectEvent $userObject)
{
$user = $userObject->getObject();
if (($user instanceof Customer)) {
$userName = $user->getName() ? $user->getName() : ' ';
$userEmail = $user->getEmail();
$companyName = $user->getOrganization() ? $user->getOrganization()->getName('en') : "";
$response = $this->c2Service->generateContact($userName, $userEmail, $companyName);
if ($response) {
if ($user->getCrmId()) {
if ($response != $user->getCrmId()) {
$user->setCrmId($response);
$user->save();
}
} else {
$user->setCrmId($response);
$user->save();
}
}
//$user->save();
}
}
}