Skip to content

Commit

Permalink
Merge pull request #929 from inbaz/develop
Browse files Browse the repository at this point in the history
fixed age change; fixed shopping cart reset after purchase
  • Loading branch information
BigAndini authored Mar 1, 2017
2 parents d00a50f + 341a128 commit a8e1f59
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 9 deletions.
13 changes: 13 additions & 0 deletions module/ErsBase/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ public function getServiceConfig() {
$service->setServiceLocator($sm);
return $service;
},
'ErsBase\Service\AgegroupService' => function($sm) {
$agegroupService = new Service\AgegroupService();
$agegroupService->setServiceLocator($sm);

return $agegroupService;
},
'ErsBase\Service\AgegroupService:price' => function($sm) {
$agegroupService = new Service\AgegroupService();
$agegroupService->setServiceLocator($sm);
$em = $sm->get('Doctrine\ORM\EntityManager');
$agegroups = $em->getRepository('ErsBase\Entity\Agegroup')
->findBy(array('price_change' => '1'));
Expand All @@ -115,6 +122,12 @@ public function getServiceConfig() {

return $agegroupService;
},
'ErsBase\Service\DeadlineService' => function($sm) {
$deadlineService = new Service\DeadlineService();
$deadlineService->setServiceLocator($sm);

return $deadlineService;
},
'ErsBase\Service\DeadlineService:price' => function($sm) {
$deadlineService = new Service\DeadlineService();
$em = $sm->get('Doctrine\ORM\EntityManager');
Expand Down
28 changes: 27 additions & 1 deletion module/ErsBase/src/ErsBase/Service/AgegroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class AgegroupService
{
protected $agegroups;
protected $mode = '';
protected $sm;

public function __construct() {
Expand All @@ -26,11 +27,36 @@ public function getServiceLocator() {
return $this->sm;
}

public function setMode($mode) {
$this->mode = $mode;
}
public function getMode() {
return $this->mode;
}

public function setAgegroups($agegroups) {
$this->agegroups = $agegroups;
}

public function getAgegroups() {
if(count($this->agegroups) <= 0) {
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$criteria = array();
switch($this->getMode()) {
case 'price':
$criteria['price_change'] = 1;
break;
case 'ticket':
$criteria['ticket_change'] = 1;
break;
default:
throw new \Exception('Please set a mode for Agegroup Service: price or ticket');
break;
}
$agegroups = $em->getRepository('ErsBase\Entity\Agegroup')
->findBy($criteria);
$this->setAgegroups($agegroups);
}
return $this->agegroups;
}

Expand All @@ -51,7 +77,7 @@ public function getAgegroupByDate(\DateTime $date = null) {
if($date == null) {
return $ret;
}
foreach($this->agegroups as $agegroup) {
foreach($this->getAgegroups() as $agegroup) {
if($date->getTimestamp() < $agegroup->getAgegroup()->getTimestamp()) {
continue;
}
Expand Down
40 changes: 39 additions & 1 deletion module/ErsBase/src/ErsBase/Service/DeadlineService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@
class DeadlineService
{
protected $deadlines = array();
protected $mode;
protected $sm;
protected $compareDate;

public function __construct() {
$this->compareDate = new \DateTime;
}

public function setServiceLocator($sm) {
$this->sm = $sm;
}
public function getServiceLocator() {
return $this->sm;
}

public function setMode($mode) {
$this->mode = $mode;
}
public function getMode() {
return $this->mode;
}

public function setCompareDate(\DateTime $compareDate) {
$this->compareDate = $compareDate;
}
Expand All @@ -32,10 +48,32 @@ public function setDeadlines($deadlines) {
$this->deadlines = $deadlines;
}

public function getDeadlines() {
if(count($this->deadlines) <= 0) {
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$criteria = array();
switch($this->getMode()) {
case 'price':
$criteria['price_change'] = 1;
break;
case 'ticket':
$criteria['ticket_change'] = 1;
break;
default:
throw new \Exception('Please set a mode for Deadline Service: price or ticket');
break;
}
$deadlines = $em->getRepository('ErsBase\Entity\Deadline')
->findBy($criteria);
$this->setDeadlines($deadlines);
}
return $this->deadlines;
}

public function getDeadline() {
$ret = null;
$now = $this->getCompareDate();
foreach($this->deadlines as $deadline) {
foreach($this->getDeadlines() as $deadline) {
if($now->getTimestamp() > $deadline->getDeadline()->getTimestamp()) {
continue;
}
Expand Down
58 changes: 54 additions & 4 deletions module/ErsBase/src/ErsBase/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,53 @@ private function createNewOrder() {
return $newOrder;
}

public function updateShoppingCart() {
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');

$debug = true;
$order = $this->getOrder();
$currency = $order->getCurrency();
foreach($order->getPackages() as $package) {
foreach($package->getItems() as $item) {
if($item->hasParentItems()) {
continue;
}
$product = $item->getProduct();
$participant = $item->getPackage()->getParticipant();

$agegroupService = $this->getServiceLocator()
->get('ErsBase\Service\AgegroupService');
$agegroupService->setMode('price');
$agegroup = $agegroupService->getAgegroupByUser($participant);
if($debug) {
if($agegroup != null) {
error_log('found agegroup: '.$agegroup->getName());
}
}

$deadlineService = $this->getServiceLocator()
->get('ErsBase\Service\DeadlineService');
$deadlineService->setMode('price');
$deadline = $deadlineService->getDeadline($order->getCreated());
if($debug) {
if($deadline != null) {
error_log('found deadline: '.$deadline->getName());
}
}

$price = $product->getProductPrice($agegroup, $deadline, $currency);
if($debug) {
error_log('price: '.$price->getCharge());
}
$item->setPrice($price->getCharge());
$em->persist($item);
}
}
$em->persist($order);
$em->flush();
}

public function changeCurrency($paramCurrency) {
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
Expand Down Expand Up @@ -138,21 +185,23 @@ public function changeCurrency($paramCurrency) {

$agegroupService = $this->getServiceLocator()
->get('ErsBase\Service\AgegroupService');
$agegroupService->setMode('price');
$agegroup = $agegroupService->getAgegroupByUser($participant);
#$agegroup = $participant->getAgegroup();

$deadlineService = $this->getServiceLocator()
->get('ErsBase\Service\DeadlineService:price');
->get('ErsBase\Service\DeadlineService');
$deadlineService->setMode('price');
$deadline = $deadlineService->getDeadline($order->getCreated());

$price = $product->getProductPrice($agegroup, $deadline, $currency);
if($debug) {
error_log('price: '.$price->getCharge());
}
$item->setPrice($price->getCharge());
$em->flush($item);
#$em->persist($item);
}
$em->flush($package);
#$em->persist($package);
}
$order->setCurrency($currency);
if($debug) {
Expand All @@ -161,7 +210,8 @@ public function changeCurrency($paramCurrency) {
if($order->getPaymentType()) {
$order->setPaymentType(null);
}
$em->flush($order);
$em->persist($order);
$em->flush();
}

return $this;
Expand Down
6 changes: 3 additions & 3 deletions module/PreReg/src/PreReg/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function paymentAction() {
->findOneBy(array('id' => $data['paymenttype_id']));

if($paymenttype->getCurrency()->getShort() != $order->getCurrency()->getShort()) {
throw new \Exception('Unable to set this payment type for this order. Please chooser another payment type.');
throw new \Exception('Unable to set this payment type for this order. Please choose another payment type.');
}

$order->setPaymentType($paymenttype);
Expand Down Expand Up @@ -466,9 +466,9 @@ public function checkoutAction() {

$em->flush();

#$container = new Container('ers');
$container = new Container('ers');
$container->checkout = array();
$container->order_id = $order->getId();
unset($container->order_id);
$container->init = 0;

$emailService = $this->getServiceLocator()
Expand Down
4 changes: 4 additions & 0 deletions module/PreReg/src/PreReg/Controller/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public function editAction()
$em->persist($participant);
$em->flush();

$orderService = $this->getServiceLocator()
->get('ErsBase\Service\OrderService');
$orderService->updateShoppingCart();

$breadcrumb = $breadcrumbService->get('participant');
return $this->redirect()->toRoute($breadcrumb->route, $breadcrumb->params, $breadcrumb->options);
} else {
Expand Down
2 changes: 2 additions & 0 deletions module/PreReg/view/pre-reg/info/terms.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $this->headTitle($this->translate('Terms & Conditions'));

<div class="jumbotron">
<h1><?php echo $this->translate('Terms and Conditions'); ?></h1>
<p>ERS Terms: <a href="/Terms-and-Conditions-ERS-EN-v5.pdf">Terms-and-Conditions-ERS-EN-v5.pdf</a><br />
ORGA Terms: <a href="/Terms-and-Conditions-ORGA-EN-v4.pdf">Terms-and-Conditions-ORGA-EN-v4.pdf</a></p>
<?php /* <a href="/Terms-and-Conditions-ERS-EN-v5.pdf" target="_blank">Terms and Conditions ERS EN v5</a><br />
<a href="/Terms-and-Conditions-ORGA-EN-v4.pdf" target="_blank">Terms and Conditions ORGA EN v4</a>*/ ?>
<h3><?php echo $this->translate('Disclaimer'); ?></h3>
Expand Down

0 comments on commit a8e1f59

Please sign in to comment.