/**
  * {@inheritdoc}
  */
 public function processEvent(TrackingVisitEvent $trackingVisitEvent)
 {
     $code = $trackingVisitEvent->getWebEvent()->getCode();
     $campaign = $this->em->getRepository('OroCRMCampaignBundle:Campaign')->findOneBy(['code' => $code]);
     if ($campaign) {
         return [$campaign];
     }
     return [];
 }
 /**
  * @dataProvider processData
  * @param $isFind
  */
 public function testProcessEvent($isFind)
 {
     $event = new TrackingVisitEvent();
     $webEvent = new TrackingEvent();
     $webEvent->setCode('test');
     $event->setWebEvent($webEvent);
     $testResult = new \stdClass();
     $repo = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->once())->method('getRepository')->with('OroCRMCampaignBundle:Campaign')->willReturn($repo);
     $repo->expects($this->once())->method('findOneBy')->with(['code' => 'test'])->willReturn($isFind ? $testResult : null);
     $this->assertEquals($isFind ? [$testResult] : [], $this->provider->processEvent($event));
 }
예제 #3
0
 /**
  * @param array|TrackingEvent[] $entities
  */
 protected function processTrackingVisits($entities)
 {
     $em = $this->getEntityManager();
     /** @var  TrackingEvent $event */
     foreach ($entities as $event) {
         $this->logger->info('Processing event - ' . $event->getId());
         $trackingVisitEvent = new TrackingVisitEvent();
         $trackingVisitEvent->setParsingCount(0);
         $trackingVisitEvent->setEvent($this->getEventType($event));
         $eventData = $event->getEventData();
         $decodedData = json_decode($eventData->getData(), true);
         $trackingVisit = $this->getTrackingVisit($event, $decodedData);
         $trackingVisitEvent->setVisit($trackingVisit);
         $trackingVisitEvent->setWebEvent($event);
         $trackingVisitEvent->setWebsite($event->getWebsite());
         $targets = $this->trackingIdentification->processEvent($trackingVisitEvent);
         if (!empty($targets)) {
             foreach ($targets as $target) {
                 $trackingVisitEvent->addAssociationTarget($target);
             }
         }
         $event->setParsed(true);
         $em->persist($event);
         $em->persist($trackingVisitEvent);
         $em->persist($trackingVisit);
     }
     $em->flush();
     $this->updateVisits($this->collectedVisits);
     $this->collectedVisits = [];
     $this->eventDictionary = [];
     $em->clear();
     $this->logger->info(sprintf('<comment>Memory usage (currently) %dMB/ (max) %dMB</comment>', round(memory_get_usage(true) / 1024 / 1024), memory_get_peak_usage(true) / 1024 / 1024));
 }
 /**
  * {@inheritdoc}
  */
 public function processEvent(TrackingVisitEvent $trackingVisitEvent)
 {
     $targets = [];
     // identifier
     $targets[] = $trackingVisitEvent->getVisit()->getIdentifierTarget();
     $channel = $trackingVisitEvent->getVisit()->getTrackingWebsite()->getChannel();
     $eventName = $trackingVisitEvent->getEvent()->getName();
     $eventValue = $trackingVisitEvent->getWebEvent()->getValue();
     switch ($eventName) {
         case self::EVENT_CART_ITEM_ADDED:
             $targets[] = $this->em->getRepository('OroCRMMagentoBundle:Product')->findOneBy(['originId' => (int) $eventValue]);
             break;
         case self::EVENT_ORDER_PLACE_SUCCESS:
             $targets[] = $this->em->getRepository('OroCRMMagentoBundle:Order')->findOneBy(['subtotalAmount' => $eventValue, 'dataChannel' => $channel]);
             break;
         case self::EVENT_ORDER_PLACED:
             $targets[] = $this->em->getRepository('OroCRMMagentoBundle:Order')->findOneBy(['incrementId' => $eventValue, 'dataChannel' => $channel]);
             break;
         case self::EVENT_CHECKOUT_STARTED:
             $targets[] = $this->em->getRepository('OroCRMMagentoBundle:Cart')->findOneBy(['subTotal' => $eventValue, 'dataChannel' => $channel]);
             break;
         case self::EVENT_CUSTOMER_LOGOUT:
             $targets[] = $this->em->getRepository('OroCRMMagentoBundle:Customer')->findOneBy(['originId' => (int) $eventValue, 'dataChannel' => $channel]);
             break;
     }
     return $targets;
 }
예제 #5
0
 public function testParsingCount()
 {
     $this->assertEquals(0, $this->trackingVisitEvent->getParsingCount());
     $this->trackingVisitEvent->setParsingCount(1);
     $this->assertEquals(1, $this->trackingVisitEvent->getParsingCount());
 }
 /**
  * @dataProvider processEventProvider
  *
  * @param $eventType
  * @param $eventValue
  * @param $repoClass
  * @param $parameters
  * @param $channel
  */
 public function testProcessEvent($eventType, $eventValue, $repoClass, $parameters, $channel)
 {
     $trackingEvent = new TrackingVisitEvent();
     $visit = new TrackingVisit();
     $channel->setChannelType(ChannelType::TYPE);
     $website = new TestTrackingWebsite();
     $website->setChannel($channel);
     $visit->setTrackingWebsite($website);
     $trackingDict = new TrackingEventDictionary();
     $trackingDict->setName($eventType);
     $trackingEvent->setEvent($trackingDict);
     $trackingEvent->setWebsite($website);
     $trackingEvent->setVisit($visit);
     $webEvent = new TrackingEvent();
     $webEvent->setValue($eventValue);
     $trackingEvent->setWebEvent($webEvent);
     $repo = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->once())->method('getRepository')->with($repoClass)->willReturn($repo);
     $repo->expects($this->once())->method('findOneBy')->with($parameters)->willReturn(new \stdClass());
     $this->provider->processEvent($trackingEvent);
 }