Skip to content

Commit

Permalink
Merge pull request #925 from inbaz/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BigAndini authored Feb 25, 2017
2 parents 1e8ab3f + d74dfc8 commit 5cd3ef7
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 54 deletions.
2 changes: 1 addition & 1 deletion config/autoload/bjyauthorize.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
['controller' => 'PreReg\Controller\Product', 'roles' => ['guest', 'user']],
['controller' => 'PreReg\Controller\Participant', 'roles' => ['guest', 'user']],
['controller' => 'PreReg\Controller\Buyer', 'roles' => ['guest', 'user']],
['controller' => 'PreReg\Controller\Ajax', 'roles' => ['guest', 'user']],
['controller' => 'PreReg\Controller\Test', 'roles' => ['admin']],

/* ZfcUser */
Expand Down Expand Up @@ -193,7 +194,6 @@
['controller' => 'Admin\Controller\Bankaccount', 'roles' => ['admin', 'supradm']],
['controller' => 'Admin\Controller\Matching', 'roles' => ['admin', 'supradm']],
['controller' => 'Admin\Controller\Ajax', 'roles' => ['admin', 'supradm']],
['controller' => 'Admin\Controller\Ajax', 'action' => 'session-storage', 'roles' => ['guest', 'user']],
['controller' => 'Admin\Controller\Refund', 'roles' => ['admin', 'supradm']],
['controller' => 'Admin\Controller\Status', 'roles' => ['admin', 'supradm']],
['controller' => 'Admin\Controller\Overview', 'roles' => ['admin', 'supradm']],
Expand Down
5 changes: 4 additions & 1 deletion module/ErsBase/src/ErsBase/Entity/ProductPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ public function __construct()
{
parent::__construct();
}


public function __toString() {
return $this->getCharge();
}
}
2 changes: 1 addition & 1 deletion module/ErsBase/src/ErsBase/Service/DeadlineService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class DeadlineService
{
protected $deadlines;
protected $deadlines = array();
protected $compareDate;

public function __construct() {
Expand Down
24 changes: 24 additions & 0 deletions module/ErsBase/src/ErsBase/Service/OptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ public function getCountryOptions($countryId = null) {
return $options;
}

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

$currencies = $em->getRepository('ErsBase\Entity\Currency')
->findBy(array('active' => 1), array('position' => 'ASC'));

$container = new Container('ers');

$options = array();
foreach($currencies as $currency) {
$selected = false;
if($container->currency == $currency->getShort()) {
$selected = true;
}
$options[] = array(
'value' => $currency->getId(),
'label' => $currency->getName(),
'selected' => $selected,
);
}
return $options;
}

public function getPersonOptions(\ErsBase\Entity\Product $product, $participant_id=null) {
$cartContainer = new Container('ers');
$options = array();
Expand Down
43 changes: 30 additions & 13 deletions module/ErsBase/src/ErsBase/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,41 @@ private function createNewOrder() {
return $newOrder;
}

public function changeCurrency(Entity\Currency $currency) {
public function changeCurrency($paramCurrency) {
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
if(! $paramCurrency instanceof Entity\Currency) {
$currency = $em->getRepository('ErsBase\Entity\Currency')
->findOneBy(array('short' => $paramCurrency));
} else {
$currency = $paramCurrency;
}
$order = $this->getOrder();
if($order->getCurrency()->getShort() != $currency->getShort()) {
foreach($order->getItems() as $item) {
$item->setCurrency($currency);
$product = $item->getProduct();
$participant = $item->getPackage()->getParticipant();

$agegroup = $participant->getAgegroup();

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

$item->setPrice($product->getProductPrice($agegroup, $deadline, $currency));
foreach($order->getPackages() as $package) {
$package->setCurrency($currency);
foreach($package->getItems() as $item) {
$item->setCurrency($currency);
$product = $item->getProduct();
$participant = $item->getPackage()->getParticipant();

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

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

$item->setPrice($product->getProductPrice($agegroup, $deadline, $currency)->getCharge());
}
}
$order->setCurrency($currency);
}
$em->flush($order);

error_log('currency changed!');
return $this;
}

Expand Down
43 changes: 15 additions & 28 deletions module/PreReg/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ public function bootstrapSession($e)

$container->currency = 'EUR';
}
#error_log('currency locale: '.$container->currency);
$serviceManager = $e->getApplication()->getServiceManager();
$orderService = $serviceManager->get('ErsBase\Service\OrderService');
$order = $orderService->getOrder();
if($order->getCurrency()->getShort() != $container->currency) {
error_log('currencies are not the same!');
$orderService->changeCurrency($container->currency);
}

/*
* shopping cart debugging
Expand Down Expand Up @@ -261,6 +267,14 @@ public function getServiceConfig() {
Container::setDefaultManager($sessionManager);
return $sessionManager;
},
'PreReg\Form\CurrencyChooser' => function ($sm) {
$form = new Form\CurrencyChooser();

$optionService = $sm->get('ErsBase\Service\OptionService');
$form->get('currency')->setValueOptions($optionService->getCurrencyOptions());

return $form;
},
'PreReg\Form\ProductView' => function ($sm) {
$productView = new Form\ProductView();
$productView->setServiceLocator($sm);
Expand Down Expand Up @@ -317,31 +331,4 @@ public function getServiceConfig() {
),
);
}
public function getViewHelperConfig()
{
return array(
'invokables' => array(
'formelementerrors' => 'PreReg\Form\View\Helper\FormElementErrors',
'checkoutactive' => 'PreReg\View\Helper\CheckoutActive',
),
'factories' => array(
'config' => function($sm) {
$helper = new \PreReg\View\Helper\Config($sm);
return $helper;
},
'session' => function($sm) {
$helper = new \PreReg\View\Helper\Session();
return $helper;
},
'checkoutactive' => function($sm) {
$helper = new \PreReg\View\Helper\CheckoutActive();
return $helper;
},
'niceiban' => function($sm) {
$helper = new \PreReg\View\Helper\NiceIban($sm);
return $helper;
},
),
);
}
}
25 changes: 25 additions & 0 deletions module/PreReg/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,29 @@
#'zfc-user' => __DIR__ . '/../view',
),
),
'view_helpers' => array(
'invokables' => array(
'formelementerrors' => 'PreReg\Form\View\Helper\FormElementErrors',
'checkoutactive' => 'PreReg\View\Helper\CheckoutActive',
'currencychooser' => 'PreReg\View\Helper\CurrencyChooser',
),
'factories' => array(
'config' => function($sm) {
$helper = new \PreReg\View\Helper\Config($sm);
return $helper;
},
'session' => function($sm) {
$helper = new \PreReg\View\Helper\Session();
return $helper;
},
'checkoutactive' => function($sm) {
$helper = new \PreReg\View\Helper\CheckoutActive();
return $helper;
},
'niceiban' => function($sm) {
$helper = new \PreReg\View\Helper\NiceIban($sm);
return $helper;
},
),
),
);
31 changes: 29 additions & 2 deletions module/PreReg/src/PreReg/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@
use ErsBase\Entity;

class ProductController extends AbstractActionController {

public function changeCurrencyAction() {
$form = new Form\CurrencyChooser();
$optionService = $this->getServiceLocator()
->get('ErsBase\Service\OptionService');
$form->get('currency')->setValueOptions($optionService->getCurrencyOptions());

$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if($form->isValid()) {
$data = $request->getPost();

$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
$currency = $em->getRepository('ErsBase\Entity\Currency')
->findOneBy(array('id' => $data['currency']));
if($currency) {
$container = new Container('ers');
$container->currency = $currency->getShort();
}
}

$redirectUrl = $this->getRequest()->getHeader('Referer')->uri()->getPath();
$this->redirect()->toUrl($redirectUrl);
}
}

public function indexAction()
{
$this->getServiceLocator()->get('ErsBase\Service\TicketCounterService')
Expand All @@ -38,7 +66,6 @@ public function indexAction()
'position' => 'ASC'
)
);

$container = new Container('ers');
$currency = $em->getRepository('ErsBase\Entity\Currency')
->findOneBy(array('short' => $container->currency));
Expand Down Expand Up @@ -187,7 +214,7 @@ public function addAction() {
$cartContainer = new Container('ers');

$formfail = false;

$request = $this->getRequest();
if ($request->isPost()) {
$inputFilter = $form->getInputFilter();
Expand Down
102 changes: 102 additions & 0 deletions module/PreReg/src/PreReg/Form/CurrencyChooser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace PreReg\Form;

use Zend\Form\Form;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Session\Container;

class CurrencyChooser extends Form implements InputFilterProviderInterface
{
protected $em;
protected $sm;
public function getEntityManager() {
return $this->em;
}
public function setEntityManager($em) {
$this->em = $em;
}

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

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


public function __construct()
{
parent::__construct('currency-chooser');

$this->setAttribute('method', 'post');

$this->add(array(
'name' => 'currency',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'required' => 'required',
'class' => 'form-control',
),
'options' => array(
/*'label' => _('Change Currency:'),
'label_attributes' => array(
'class' => 'media-object',
),*/
),
));

$this->add(array(
'name' => 'csrf',
'type' => 'Zend\Form\Element\Csrf',
));

$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => _('Go'),
'id' => 'submitbutton',
'class' => 'btn btn-primary',
),
));
}

/**
* Should return an array specification compatible with
* {@link Zend\InputFilter\Factory::createInputFilter()}.
*
* @return array
*/
public function getInputFilterSpecification()
{
return array(
'currency' => array(
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
'validators' => array(
),
),
/*'price' => array(
'required' => true,
'validators' => array(
array(
'name' => 'Float',
),
),
),*/
);
}
}
Loading

0 comments on commit 5cd3ef7

Please sign in to comment.