<?php
namespace App\EventListener\Analitics;
use App\Entity\Gos\Cart;
use App\Event\Analitics\AddPaymentInfoEvent;
use App\Utils\FacebookPixel\Api\FacebookPixelService;
use App\Utils\Uniqskills\MixPanel\MixPanelService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddPaymentInfoListener implements EventSubscriberInterface
{
private $entityManager;
private $mixPanelService;
private $facebookPixelService;
public function __construct(
EntityManagerInterface $entityManager,
MixPanelService $mixPanelService,
FacebookPixelService $facebookPixelService
) {
$this->entityManager = $entityManager;
$this->mixPanelService = $mixPanelService;
$this->facebookPixelService = $facebookPixelService;
}
public static function getSubscribedEvents(): array
{
return [
AddPaymentInfoEvent::CART_ADD_PAYMENT_INFO => [
['sendMixPixel', 10],
['sendFacebookPixel', 9]
],
];
}
public function sendMixPixel($event): void
{
$cartHash = $event->getCartHash();
$cart = $this->entityManager->getRepository(Cart::class)->findOneByHash($cartHash);
$this->mixPanelService->sendCartRenderEvent([
'step' => 'address',
'products' => $price ?? null,
], $cart->getUser());
}
public function sendFacebookPixel($event)
{
$cartHash = $event->getCartHash();
$cart = $this->entityManager->getRepository(Cart::class)->findOneByHash($cartHash);
$this->facebookPixelService->setEvent('AddPaymentInfo', $cart->getId())->request();
}
}