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; }
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; }
/** * Creates a form to update a Orders Status entity. * * @param Orders $order The entity * * @return \Symfony\Component\Form\Form The form */ private function createStatusForm(Orders $order) { $form = $this->createFormBuilder()->setAction($this->generateUrl('orders_status_update', array('id' => $order->getId())))->setMethod('PUT'); $children = $order->getOrderState()->getAvailableStates(); $companionsCount = $order->getOrderCompanions()->count() > 1 ? true : false; if (is_array($children)) { $postable = $this->isPostable($order->getId()); foreach ($children as $key => $child) { if ("post" == $child->getKey() && false == $postable) { unset($child); continue; } if (("approved" == $child->getKey() || "rejected" == $child->getKey()) && $companionsCount) { $form->add($child->getKey(), 'button', array('label' => $child->getName(), 'attr' => array('id' => 'state_' . $key, 'class' => 'ml-5 btn-group btn-' . $child->getBootstrapClass(), 'value' => $child->getKey(), 'data-toggle' => "modal", 'data-target' => "#approvalModal"))); } else { $form->add($child->getKey(), 'submit', array('label' => $child->getName(), 'attr' => array('id' => 'state_' . $key, 'class' => 'ml-5 btn-group btn-' . $child->getBootstrapClass(), 'value' => $child->getKey()))); } } } return $form->getForm(); }