Пример #1
0
 public function acceptParticipantChangeAction()
 {
     $logger = $this->getServiceLocator()->get('Logger');
     $user_id = (int) $this->params()->fromQuery('user_id', 0);
     $item_id = (int) $this->params()->fromQuery('item_id', 0);
     $form = new Form\AcceptParticipantChangeItem();
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $inputFilter = $this->getServiceLocator()->get('Admin\\InputFilter\\AcceptParticipantChangeItem');
         #$form->setInputFilter($inputFilter->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('id' => $data['user_id']));
             $item = $em->getRepository("ErsBase\\Entity\\Item")->findOneBy(array('id' => $data['item_id']));
             $log = new Entity\Log();
             $log->setUser($this->zfcUserAuthentication()->getIdentity());
             $log->setData('changed participant for item ' . $item->getCode()->getValue() . ': ' . $data['comment']);
             $em->persist($log);
             #$em->flush();
             $package = $item->getPackage();
             # initialize new package
             $newPackage = new Entity\Package();
             $code = new Entity\Code();
             $code->genCode();
             $codecheck = 1;
             while ($codecheck != null) {
                 $code->genCode();
                 $codecheck = $em->getRepository("ErsBase\\Entity\\Code")->findOneBy(array('value' => $code->getValue()));
             }
             $newPackage->setCode($code);
             # set order for package
             $newPackage->setOrder($package->getOrder());
             $cloneService = $this->getServiceLocator()->get('ErsBase\\Service\\CloneService');
             $cloneService->setTransfer(true);
             $newItem = $cloneService->cloneItem($item);
             #$newItem = clone $item;
             $newPackage->addItem($newItem);
             $item->setStatus('transferred');
             #$item->setTransferredItem($newItem);
             $code = new Entity\Code();
             $code->genCode();
             $codecheck = 1;
             while ($codecheck != null) {
                 $code->genCode();
                 $codecheck = $em->getRepository("ErsBase\\Entity\\Code")->findOneBy(array('value' => $code->getValue()));
             }
             $newItem->setCode($code);
             $em->persist($item);
             $em->persist($newItem);
             #$newPackage->setTransferredPackage($package);
             $newPackage->setParticipant($user);
             $em->persist($newPackage);
             #$em->persist($package);
             $em->flush();
             $order = $package->getOrder();
             return $this->redirect()->toRoute('admin/order', array('action' => 'detail', 'id' => $order->getId()));
         } else {
             $logger->warn($form->getMessages());
         }
     }
     $user = null;
     if ($user_id != 0) {
         $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('id' => $user_id));
     }
     $item = null;
     if ($item_id != 0) {
         $item = $em->getRepository("ErsBase\\Entity\\Item")->findOneBy(array('id' => $item_id));
     }
     $form->get('item_id')->setValue($item->getId());
     $form->get('user_id')->setValue($user->getId());
     $forrest = new Service\BreadcrumbService();
     if (!$forrest->exists('item')) {
         $forrest->set('item', 'admin/order', array('action' => 'search'));
     }
     return new ViewModel(array('form' => $form, 'user' => $user, 'item' => $item, 'breadcrumb' => $forrest->get('package')));
 }
Пример #2
0
 public function acceptBuyerChangeAction()
 {
     $logger = $this->getServiceLocator()->get('Logger');
     $user_id = (int) $this->params()->fromQuery('user_id', 0);
     $order_id = (int) $this->params()->fromQuery('order_id', 0);
     $form = new Form\AcceptBuyerChange();
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $inputFilter = $this->getServiceLocator()->get('Admin\\InputFilter\\AcceptBuyerChange');
         #$inputFilter = new InputFilter\AcceptBuyerChange();
         #$form->setInputFilter($inputFilter->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('id' => $data['user_id']));
             $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => $data['order_id']));
             $log = new Entity\Log();
             $log->setUser($this->zfcUserAuthentication()->getIdentity());
             $log->setData('changed buyer for order ' . $order->getCode()->getValue() . ': ' . $data['comment']);
             $em->persist($log);
             $em->flush();
             $order->setBuyer($user);
             $em->persist($order);
             $em->flush();
             return $this->redirect()->toRoute('admin/order', array('action' => 'detail', 'id' => $order->getId()));
         } else {
             $logger->warn($form->getMessages());
         }
     }
     $user = null;
     if ($user_id != 0) {
         $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('id' => $user_id));
     }
     $order = null;
     if ($order_id != 0) {
         $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => $order_id));
     }
     $form->get('order_id')->setValue($order->getId());
     $form->get('user_id')->setValue($user->getId());
     $forrest = new Service\BreadcrumbService();
     if (!$forrest->exists('order')) {
         $forrest->set('order', 'admin/order', array('action' => 'search'));
     }
     return new ViewModel(array('form' => $form, 'user' => $user, 'order' => $order, 'breadcrumb' => $forrest->get('order')));
 }
Пример #3
0
 public function checkoutAction()
 {
     $container = new Container('initialized');
     if (!is_array($container->checkout)) {
         $container->checkout = array();
     }
     $container->checkout['/order/checkout'] = 1;
     $cartContainer = new Container('cart');
     $orderContainer = new Container('order');
     $orderService = $this->getServiceLocator()->get('ErsBase\\Service\\OrderService');
     $order = $orderService->getOrder();
     #$this->checkItemPrices();
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $paymenttype = $em->getRepository("ErsBase\\Entity\\PaymentType")->findOneBy(array('id' => $order->getPaymentTypeId()));
     $order->setPaymentType($paymenttype);
     if (isset($orderContainer->order_id)) {
         $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => $orderContainer->order_id));
         if ($order) {
             return $this->redirect()->toRoute('order', array('action' => 'view', 'hashkey' => $order->getHashkey()));
         }
     }
     $form = new Form\Checkout();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $inputFilter = new InputFilter\Checkout();
         $form->setInputFilter($inputFilter->getInputFilter());
         $form->setData($request->getPost());
         foreach ($order->getPackages() as $package) {
             if (count($package->getItems()) <= 0) {
                 $order->removePackage($package);
                 $em->remove($package);
                 continue;
             }
             $participant = $package->getParticipant();
             if ($participant->getFirstname() == '' || $participant->getSurname() == '') {
                 $participant = $buyer;
             }
             $user = null;
             if ($participant->getEmail() == '') {
                 $participant->setEmail(null);
             } else {
                 $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('email' => $participant->getEmail()));
             }
             $role = $em->getRepository("ErsBase\\Entity\\Role")->findOneBy(array('roleId' => 'participant'));
             if ($user instanceof Entity\User) {
                 $package->setParticipant($user);
                 if (!$user->hasRole($role)) {
                     $user->addRole($role);
                     $em->persist($user);
                 }
                 #$package->setParticipantId($user->getId());
             } else {
                 $em->persist($participant);
                 $package->setParticipant($participant);
                 #$package->setParticipantId($participant->getId());
             }
             $country = $em->getRepository("ErsBase\\Entity\\Country")->findOneBy(array('id' => $participant->getCountryId()));
             if (!$country) {
                 $participant->setCountry(null);
             } else {
                 $participant->setCountry($country);
             }
         }
         $status = $em->getRepository('ErsBase\\Entity\\Status')->findOneBy(array('value' => 'ordered'));
         $order->setStatus($status);
         $em->persist($order);
         # add log entry
         $log = new Entity\Log();
         $log->setOrder($order);
         $log->setUser($order->getBuyer());
         $log->setData($order->getCode()->getValue() . ' ordered');
         $em->persist($log);
         $em->flush();
         $orderContainer->order_id = $order->getId();
         $cartContainer->init = 0;
         $emailService = $this->getServiceLocator()->get('ErsBase\\Service\\EmailService');
         $emailService->sendConfirmationEmail($order->getId());
         $forrest = new Service\BreadcrumbService();
         $forrest->remove('terms');
         switch (strtolower($order->getPaymentType()->getType())) {
             case 'banktransfer':
                 return $this->redirect()->toRoute('payment', array('action' => 'banktransfer', 'hashkey' => $order->getHashkey()));
             case 'cheque':
                 return $this->redirect()->toRoute('payment', array('action' => 'cheque', 'hashkey' => $order->getHashkey()));
             case 'creditcard':
                 return $this->redirect()->toRoute('payment', array('action' => 'creditcard', 'hashkey' => $order->getHashkey()));
             case 'paypal':
                 return $this->redirect()->toRoute('payment', array('action' => 'paypal', 'hashkey' => $order->getHashkey()));
                 break;
             default:
         }
     }
     $forrest = new Service\BreadcrumbService();
     $forrest->set('terms', 'order', array('action' => 'checkout'));
     /*
      * Check the buyers email, if it's not valid, delete buyer
      */
     $email_validator = new Validator\EmailAddress();
     $buyer = $order->getBuyer();
     if ($buyer) {
         $email = $order->getBuyer()->getEmail();
         if (!$email_validator->isValid($email)) {
             $order->setBuyer();
         }
     }
     return new ViewModel(array('form' => $form, 'order' => $order));
 }