예제 #1
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());
         }
     }
 }