diff --git a/config/autoload/bjyauthorize.global.php b/config/autoload/bjyauthorize.global.php index ea18885a..16e2f233 100644 --- a/config/autoload/bjyauthorize.global.php +++ b/config/autoload/bjyauthorize.global.php @@ -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 */ @@ -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']], diff --git a/module/ErsBase/src/ErsBase/Entity/ProductPrice.php b/module/ErsBase/src/ErsBase/Entity/ProductPrice.php index f59c00ed..68e19f86 100644 --- a/module/ErsBase/src/ErsBase/Entity/ProductPrice.php +++ b/module/ErsBase/src/ErsBase/Entity/ProductPrice.php @@ -24,5 +24,8 @@ public function __construct() { parent::__construct(); } - + + public function __toString() { + return $this->getCharge(); + } } \ No newline at end of file diff --git a/module/ErsBase/src/ErsBase/Service/DeadlineService.php b/module/ErsBase/src/ErsBase/Service/DeadlineService.php index 0498a5be..5786a07f 100644 --- a/module/ErsBase/src/ErsBase/Service/DeadlineService.php +++ b/module/ErsBase/src/ErsBase/Service/DeadlineService.php @@ -13,7 +13,7 @@ class DeadlineService { - protected $deadlines; + protected $deadlines = array(); protected $compareDate; public function __construct() { diff --git a/module/ErsBase/src/ErsBase/Service/OptionService.php b/module/ErsBase/src/ErsBase/Service/OptionService.php index aad90e29..371d246c 100644 --- a/module/ErsBase/src/ErsBase/Service/OptionService.php +++ b/module/ErsBase/src/ErsBase/Service/OptionService.php @@ -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(); diff --git a/module/ErsBase/src/ErsBase/Service/OrderService.php b/module/ErsBase/src/ErsBase/Service/OrderService.php index d5c15acf..cddc165a 100644 --- a/module/ErsBase/src/ErsBase/Service/OrderService.php +++ b/module/ErsBase/src/ErsBase/Service/OrderService.php @@ -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; } diff --git a/module/PreReg/Module.php b/module/PreReg/Module.php index 27d7a38f..90f44020 100644 --- a/module/PreReg/Module.php +++ b/module/PreReg/Module.php @@ -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 @@ -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); @@ -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; - }, - ), - ); - } } \ No newline at end of file diff --git a/module/PreReg/config/module.config.php b/module/PreReg/config/module.config.php index d8c8aba7..628763ff 100644 --- a/module/PreReg/config/module.config.php +++ b/module/PreReg/config/module.config.php @@ -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; + }, + ), + ), ); diff --git a/module/PreReg/src/PreReg/Controller/ProductController.php b/module/PreReg/src/PreReg/Controller/ProductController.php index e7b4c9c4..94586dd8 100644 --- a/module/PreReg/src/PreReg/Controller/ProductController.php +++ b/module/PreReg/src/PreReg/Controller/ProductController.php @@ -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') @@ -38,7 +66,6 @@ public function indexAction() 'position' => 'ASC' ) ); - $container = new Container('ers'); $currency = $em->getRepository('ErsBase\Entity\Currency') ->findOneBy(array('short' => $container->currency)); @@ -187,7 +214,7 @@ public function addAction() { $cartContainer = new Container('ers'); $formfail = false; - + $request = $this->getRequest(); if ($request->isPost()) { $inputFilter = $form->getInputFilter(); diff --git a/module/PreReg/src/PreReg/Form/CurrencyChooser.php b/module/PreReg/src/PreReg/Form/CurrencyChooser.php new file mode 100644 index 00000000..c113331a --- /dev/null +++ b/module/PreReg/src/PreReg/Form/CurrencyChooser.php @@ -0,0 +1,102 @@ +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', + ), + ), + ),*/ + ); + } +} diff --git a/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php b/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php new file mode 100644 index 00000000..c85337f0 --- /dev/null +++ b/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php @@ -0,0 +1,53 @@ +. + */ + +namespace PreReg\View\Helper; + +use Zend\View\Helper\AbstractHelper; +#use Zend\View\HelperPluginManager as ServiceManager; +use Zend\Session\Container; +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class CurrencyChooser extends AbstractHelper implements ServiceLocatorAwareInterface{ + + protected $sm; + + public function __construct() { + #$this->sm = $sm; + } + + public function setServiceLocator(ServiceLocatorInterface $sm) { + $this->sm = $sm; + } + public function getServiceLocator() { + return $this->sm; + } + + public function __invoke() { + if(!$this->getServiceLocator()) { + throw new \Exception('ServiceLocator is needed for Currency Chooser'); + } + # two times getServiceLocator because the first one is just the PluginManager, + # the second one is the ApplicationManager + return $this->getServiceLocator()->getServiceLocator() + ->get('PreReg\Form\CurrencyChooser'); + } + +} \ No newline at end of file diff --git a/module/PreReg/view/partial/currency-chooser.phtml b/module/PreReg/view/partial/currency-chooser.phtml new file mode 100644 index 00000000..7bdc2f65 --- /dev/null +++ b/module/PreReg/view/partial/currency-chooser.phtml @@ -0,0 +1,16 @@ +setAttribute('action', $this->url('product', array('action' => 'change-currency'))); +$form->prepare(); + +echo $this->form()->openTag($form); ?> +
translate('The prices will increase after
%s'), $deadline->getDeadline()->format('d.m.Y H:i:s T')); ?>
+
+ partial('partial/currency-chooser.phtml', array('form' => $this->currencychooser())); ?> +
partial('partial/product-price.phtml', array('agegroups' => $agegroups, 'deadline' => $deadline, 'product' => $product)); ?>translate('The prices will increase after'); ?>
getDeadline()->format('d.m.Y H:i:s T'); ?>
+ Show prices in: + +
partial('partial/product-price.phtml', array('agegroups' => $agegroups, 'deadline' => $deadline, 'product' => $product)); ?>translate('Click on any item to add further information and place it in your shopping cart.'); ?>
translate('The prices will increase after
%s'), $deadline->getDeadline()->format('d.m.Y H:i:s T')); ?>
+ partial('partial/currency-chooser.phtml', array('form' => $currencyChooser)); ?> + partial('partial/currency-chooser.phtml', array('form' => $this->currencychooser())); ?> + form()->openTag($currencyChooser); + #echo $this->formCollection($currencyChooser); + #echo $this->form()->closeTag(); + #$ccForm = $this->currencyChooser; + /*$currencyChooser->setAttribute('action', $this->url('product', array('action' => 'change-currency'))); + $currencyChooser->prepare(); + + echo $this->form()->openTag($currencyChooser); + echo $this->formRow($currencyChooser->get('currency')); + echo $this->formHidden($currencyChooser->get('csrf')); + echo $this->formSubmit($currencyChooser->get('submit')); + echo $this->form()->closeTag();*/ + ?> +