public function testInterface()
 {
     $channel = new Integration();
     $someOwner = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\User');
     $channel->setDefaultUserOwner($someOwner);
     $event = new DefaultOwnerSetEvent($channel);
     $this->assertSame($channel, $event->getChannel());
     $this->assertSame($someOwner, $event->getDefaultUserOwner());
 }
Esempio n. 2
0
 /**
  * @param DefaultOwnerSetEvent $event
  */
 public function onSet(DefaultOwnerSetEvent $event)
 {
     $channel = $event->getChannel();
     // process only magento channels
     if ($channel->getType() !== ChannelType::TYPE) {
         return;
     }
     // update contacts related to current channel
     // skip if owner is already set manually
     $qb = $this->em->createQueryBuilder();
     $qb->update('OroCRMContactBundle:Contact', 'c')->set('c.owner', $event->getDefaultUserOwner()->getId())->where($qb->expr()->isNull('c.owner'))->andWhere($qb->expr()->exists($this->em->createQueryBuilder()->select('mc.id')->from('OroCRMMagentoBundle:Customer', 'mc')->where('mc.channel = :channel')->setParameter('channel', $channel)->andWhere('mc.contact = c.id')))->setParameter('channel', $channel);
     $qb->getQuery()->execute();
     // update accounts related to current channel
     // skip if owner is already set manually
     $qb = $this->em->createQueryBuilder();
     $qb->update('OroCRMAccountBundle:Account', 'a')->set('a.owner', $event->getDefaultUserOwner()->getId())->where($qb->expr()->isNull('a.owner'))->andWhere($qb->expr()->exists($this->em->createQueryBuilder()->select('mc.id')->from('OroCRMMagentoBundle:Customer', 'mc')->where('mc.channel = :channel')->setParameter('channel', $channel)->andWhere('mc.account = a.id')))->setParameter('channel', $channel);
     $qb->getQuery()->execute();
     $magentoEntities = ['OroCRMMagentoBundle:Customer', 'OroCRMMagentoBundle:Cart', 'OroCRMMagentoBundle:Order'];
     foreach ($magentoEntities as $entity) {
         $this->updateMagentoEntity($entity, $channel, $event->getDefaultUserOwner()->getId());
     }
 }