/** * @param EntityManager $entityManager * @param Customer $customer */ protected function recalculateCustomerLifetime(EntityManager $entityManager, Customer $customer) { $oldLifetime = $customer->getLifetime(); /** @var OrderRepository $orderRepository */ $orderRepository = $entityManager->getRepository('OroCRMMagentoBundle:Order'); $newLifetime = $orderRepository->getCustomerOrdersSubtotalAmount($customer); if ($newLifetime != $oldLifetime) { $entityManager->getUnitOfWork()->scheduleExtraUpdate($customer, array('lifetime' => array($oldLifetime, $newLifetime))); } }