示例#1
0
 public function newOrder($em, $modxOrder)
 {
     $timezone = new \DateTimeZone('UTC');
     $order = new Orders();
     $customer = new Customers();
     $customer->setName($modxOrder['name'] . ' ' . $modxOrder['famil']);
     $customer->setEmail($modxOrder['email']);
     $customer->setPhone($modxOrder['phone']);
     $customerExists = $em->getRepository('MeVisaCRMBundle:Customers')->findOneBy(array('email' => $customer->getEmail()));
     if (!$customerExists) {
         $em->persist($customer);
         $order->setCustomer($customer);
     } else {
         $order->setCustomer($customerExists);
         $orderCommentText = '';
         // Emails do not match
         if ($customer->getName() != $customerExists->getName()) {
             //TODO: do something
             //$customerExists->setName($customer->getName());
         }
         if ($customer->getEmail() != $customerExists->getEmail()) {
             //TODO: do something
         }
         // Phones do not match
         if ($customer->getPhone() != $customerExists->getPhone()) {
             //TODO: do something
             $customerExists->setPhone($customer->getPhone());
         }
         if ('' != $orderCommentText) {
             $orderComment = new OrderComments();
             $orderComment->setComment($orderCommentText);
             $order->addOrderComment($orderComment);
         }
     }
     $this->setOrderDetails($modxOrder, $order, $timezone, $em);
     return $order;
 }
示例#2
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;
 }