Skip to content

Commit

Permalink
corrected order service
Browse files Browse the repository at this point in the history
  • Loading branch information
BigAndini committed Feb 12, 2017
1 parent a7a4e36 commit 258c792
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
30 changes: 30 additions & 0 deletions data/status.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# add roles
INSERT INTO `role` (`id`, `parent_id`, `roleId`, `active`, `updated`, `created`) VALUES
(NULL, NULL, 'onsitereg', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00'),
(NULL, NULL, 'supradm', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00'),
(NULL, NULL, 'preregcoordinator', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00'),
(NULL, NULL, 'user', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00'),
(NULL, NULL, 'admin', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00'),
(NULL, NULL, 'guest', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00'),
(NULL, NULL, 'participant', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00');
(NULL, NULL, 'buyer', 1, '2017-02-11 13:37:00', '2017-02-11 13:37:00');

# add admin user: [email protected]
# tax examples
# deadline examples
# agegroup examples

# add status
INSERT INTO `status` (`id`, `position`, `value`, `description`, `updated`, `created`, `active`) VALUES
(1, 1, 'order pending', '', NULL, NULL, 0),
(2, 2, 'ordered', '', NULL, NULL, 1),
(3, 3, 'paid', '', NULL, NULL, 1),
(4, 4, 'shipped', '', NULL, NULL, 1),
(5, 5, 'cancelled', '', NULL, NULL, 0),
(6, 6, 'transferred', '', NULL, NULL, 0);

INSERT INTO `user` (`id`, `username`, `email`, `email_status`, `display_name`, `firstname`, `surname`, `gender`, `Country_id`, `password`, `hashkey`, `state`, `active`, `birthday`, `login_count`, `newsletter`, `updated`, `created`) VALUES
(NULL, NULL, '[email protected]', NULL, NULL, 'Andi', 'Nitsche', NULL, NULL, NULL, NULL, NULL, '1', NULL, NULL, NULL, '2017-02-11 00:00:00', '2017-02-11 00:00:00');

INSERT INTO `user_has_role` (`user_id`, `role_id`) VALUES
('1', '5');
59 changes: 28 additions & 31 deletions module/ErsBase/src/ErsBase/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,37 @@ public function getOrder() {
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
if(isset($cartContainer->order_id) && is_numeric($cartContainer->order_id)) {
$order = $em->getRepository('ErsBase\Entity\Order')
$checkOrder = $em->getRepository('ErsBase\Entity\Order')
->findOneBy(array('id' => $cartContainer->order_id));
if(!$order) {
# Cannot find order with given id: Creating new order...
$order = new Entity\Order();
$status = $em->getRepository('ErsBase\Entity\Status')
->findOneBy(array('value' => 'order pending'));
$order->setStatus($status);

$em->persist($order);
$em->flush();

$cartContainer->order_id = $order->getId();
if($checkOrder) {
$this->order = $checkOrder;
$this->addLoggedInUser();
return $checkOrder;
}

$this->order = $order;
$this->addLoggedInUser();
return $order;
} else {
$order = new Entity\Order();
$status = $em->getRepository('ErsBase\Entity\Status')
->findOneBy(array('value' => 'order pending'));
$order->setStatus($status);

$em->persist($order);
$em->flush();

$cartContainer->order_id = $order->getId();

$this->order = $order;
$this->addLoggedInUser();

return $order;
}

$newOrder = $this->createNewOrder();

$cartContainer->order_id = $newOrder->getId();

$this->order = $newOrder;
$this->addLoggedInUser();

return $newOrder;
}

private function createNewOrder() {
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
$newOrder = new Entity\Order();
$status = $em->getRepository('ErsBase\Entity\Status')
->findOneBy(array('value' => 'order pending'));
$newOrder->setStatus($status);

$em->persist($newOrder);
$em->flush();

return $newOrder;
}

public function addLoggedInUser() {
Expand Down
11 changes: 0 additions & 11 deletions module/PreReg/src/PreReg/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ public function indexAction()
));
}

/*
* initialize shopping cart
*/
/*private function initializeCart() {
$cartContainer = new Container('cart');
if(!isset($cartContainer->init) && $cartContainer->init == 1) {
$cartContainer->order = new Entity\Order();
$cartContainer->init = 1;
}
}*/

public function addAction() {
$this->getServiceLocator()->get('ErsBase\Service\TicketCounterService')
->checkLimits();
Expand Down

0 comments on commit 258c792

Please sign in to comment.