示例#1
0
 public function newOrder($em, $wcOrder)
 {
     $timezone = new \DateTimeZone('UTC');
     $order = new Orders();
     $customer = new Customers();
     $customer->setName($wcOrder['billing_address']['first_name'] . ' ' . $wcOrder['billing_address']['last_name']);
     $customer->setEmail($wcOrder['billing_address']['email']);
     $customer->setPhone($wcOrder['billing_address']['phone']);
     $customerExists = $em->getRepository('MeVisaCRMBundle:Customers')->findOneBy(array('name' => $customer->getName()));
     if (!$customerExists) {
         $em->persist($customer);
         $order->setCustomer($customer);
     } else {
         $order->setCustomer($customerExists);
         $orderCommentText = '';
         // Emails do not match
         if ($customer->getEmail() != $customerExists->getEmail()) {
             $orderCommentText .= 'Email do not match, new email: ' . $customer->getEmail();
         }
         // Phones do not match
         if ($customer->getPhone() != $customerExists->getPhone()) {
             $orderCommentText .= 'Phone do not match, new phone: ' . $customer->getPhone();
         }
         if ('' != $orderCommentText) {
             $orderComment = new OrderComments();
             $orderComment->setComment($orderCommentText);
             $order->addOrderComment($orderComment);
         }
     }
     $this->setOrderDetails($wcOrder, $order, $timezone, $em);
     return $order;
 }