This topic contains 3 replies, has 3 voices, and was last updated by roberto.taschetto 5 years, 6 months ago.
- Topic
I am trying to mark any opportunity as won or lost are closed all tasks listed on that opportunity.
For this I have made an extended bundle of Opportunity Bundle that has an event that it enters when an opportunity is saved but I can not get the list of tasks of that opportunity to close it.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748namespace MtcOpportunityBundle\Listener;use Doctrine\ORM\Event\OnFlushEventArgs;use Oro\Bundle\SalesBundle\Entity\Opportunity;use Oro\Bundle\TaskBundle\Entity\Task;class Finalizado{public function onFlush(OnFlushEventArgs $args){$em = $args->getEntityManager();$uow = $em->getUnitOfWork();// we would like to listen on insertions and updates events$entities = array_merge($uow->getScheduledEntityInsertions(),$uow->getScheduledEntityUpdates());foreach ($entities as $entity) {// every time we update or insert a new ContactEmail entity we do the workif (!$entity instanceof Opportunity) {continue;}foreach($entity->tasks as $task){if(!$task instanceof Task){continue;}$task->status_id = 'closed';$em->persist($task);$md = $em->getClassMetadata(get_class($task));$uow->computeChangeSet($md, $owner);}// ... update social info of the owner with its primary email// force persist/*$em->persist($owner);$md = $em->getClassMetadata(get_class($owner));$uow->computeChangeSet($md, $owner);*/}}}
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.