/** * @expectedException \RuntimeException * @expectedExceptionMessage UOW is missing, listener is not initialized */ public function testScheduleEntityUpdateFailed() { $account = $this->getMock('OroCRM\\Bundle\\AccountBundle\\Entity\\Account'); $channel = $this->getMock('OroCRM\\Bundle\\ChannelBundle\\Entity\\Channel'); $customer = new CustomerEntity(); $customer->setAccount($account)->setDataChannel($channel); $this->channelDoctrineListener->scheduleEntityUpdate($customer, $account, $channel); }
/** * @param EntityManager $entityManager * @param Order $order */ protected function updateCustomerLifetime(EntityManager $entityManager, Order $order) { /** @var CustomerRepository $customerRepository */ $customerRepository = $entityManager->getRepository('OroCRMMagentoBundle:Customer'); $subtotalAmount = $order->getSubtotalAmount(); if ($subtotalAmount) { $discountAmount = $order->getDiscountAmount(); $lifetimeValue = $discountAmount ? $subtotalAmount - abs($discountAmount) : $subtotalAmount; // if order status changed to canceled we should remove order lifetime value from customer lifetime if ($order->isCanceled()) { $lifetimeValue *= -1; } $customer = $order->getCustomer(); $customerRepository->updateCustomerLifetimeValue($customer, $lifetimeValue); // schedule lifetime history update if ($customer->getAccount()) { $this->channelDoctrineListener->scheduleEntityUpdate($customer, $customer->getAccount(), $customer->getDataChannel()); } } }