/**
  * @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);
 }
Beispiel #2
0
 public function testNotScheduleLifetimeValueHistoryWithoutAccount()
 {
     $expectedLifetime = 200;
     $order = new Order();
     $customer = new Customer();
     $order->setCustomer($customer)->setSubtotalAmount($expectedLifetime);
     $entityManager = $this->createEntityManagerMock();
     $this->customerRepository->expects($this->once())->method('updateCustomerLifetimeValue')->with($this->isInstanceOf('OroCRM\\Bundle\\MagentoBundle\\Entity\\Customer'), $expectedLifetime);
     $this->listener->expects($this->never())->method('scheduleEntityUpdate');
     $listener = new OrderListener($this->listener);
     $listener->prePersist(new LifecycleEventArgs($order, $entityManager));
 }
Beispiel #3
0
 /**
  * @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());
         }
     }
 }