From 7943fa32bf217c183ca637bbb84dd3f5cf372d75 Mon Sep 17 00:00:00 2001 From: Andi Nitsche Date: Sat, 25 Feb 2017 13:03:47 +0100 Subject: [PATCH 1/2] added currency chooser --- .../src/PreReg/Form/CurrencyChooser.php | 380 ++++++++++++++++++ .../PreReg/View/Helper/CurrencyChooser.php | 39 ++ .../view/partial/currency-chooser.phtml | 62 +++ 3 files changed, 481 insertions(+) create mode 100644 module/PreReg/src/PreReg/Form/CurrencyChooser.php create mode 100644 module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php create mode 100644 module/PreReg/view/partial/currency-chooser.phtml diff --git a/module/PreReg/src/PreReg/Form/CurrencyChooser.php b/module/PreReg/src/PreReg/Form/CurrencyChooser.php new file mode 100644 index 00000000..92c767db --- /dev/null +++ b/module/PreReg/src/PreReg/Form/CurrencyChooser.php @@ -0,0 +1,380 @@ +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('Participant'); + + $this->setAttribute('method', 'post'); + + $this->add(array( + 'name' => 'id', + 'attributes' => array( + 'type' => 'hidden', + ), + )); + + $this->add(array( + 'name' => 'firstname', + 'type' => 'Zend\Form\Element\Text', + 'attributes' => array( + 'placeholder' => _('First name...'), + 'required' => 'required', + 'class' => 'form-control form-element', + ), + 'options' => array( + 'label' => _('First name'), + 'label_attributes' => array( + 'class' => 'media-object', + ), + ), + )); + + $this->add(array( + 'name' => 'surname', + 'type' => 'Zend\Form\Element\Text', + 'attributes' => array( + 'placeholder' => _('Surname...'), + 'required' => 'required', + 'class' => 'form-control form-element', + ), + 'options' => array( + 'label' => _('Surname'), + 'label_attributes' => array( + 'class' => 'media-object', + ), + ), + )); + + $this->add(array( + 'name' => 'birthday', + #'type' => 'Zend\Form\Element\Date', + #'type' => 'Zend\Form\Element\Text', + 'type' => 'PreReg\Form\Element\DateText', + 'attributes' => array( + 'placeholder' => _('Birthday...'), + 'required' => 'required', + 'class' => 'form-control form-element datepicker', + #'min' => '1900-01-01', + #'max' => 2015-08-09, + #'step' => '1', + ), + 'options' => array( + 'label' => _('Date of birth'), + 'label_attributes' => array( + 'class' => 'media-object', + ), + ), + )); + #$this->get('birthday')->setFormat('Y-m-d'); + $this->get('birthday')->setFormat('d.m.Y'); + + $this->add(array( + 'name' => 'email', + 'type' => 'Zend\Form\Element\Email', + 'attributes' => array( + 'placeholder' => _('Email Address...'), + #'required' => 'required', + 'class' => 'form-control form-element', + ), + 'options' => array( + 'label' => _('Email (optional)'), + 'label_attributes' => array( + 'class' => 'media-object', + ), + ), + )); + + $this->add(array( + 'name' => 'newsletter', + 'type' => 'Zend\Form\Element\Checkbox', + 'attributes' => array( + 'value' => '0', + 'class' => 'form-control form-element', + ), + 'options' => array( + 'label' => _('I\'d like to receive information about the next EJC.'), + 'label_attributes' => array( + 'class' => 'media-object', + ), + 'use_hidden_element' => true, + 'checked_value' => 1, + 'unchecked_value' => 0, + ), + )); + + $this->add(array( + 'name' => 'Country_id', + 'type' => 'Zend\Form\Element\Select', + 'attributes' => array( + 'required' => 'required', + 'class' => 'form-control form-element', + ), + 'options' => array( + 'label' => _('Where are you from?'), + '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' => _('Save'), + '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( + 'id' => array( + 'required' => false, + 'validators' => array( + ), + ), + 'firstname' => array( + 'required' => true, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'encoding' => 'UTF-8', + 'min' => 1, + 'max' => 45, + ), + ), + array ( + 'name' => 'Callback', + 'options' => array( + 'messages' => array( + \Zend\Validator\Callback::INVALID_VALUE => _('The provided name contains invalid character. These charaters are not allowed:').' !"§$%()=<>|^;{}[]', + ), + 'callback' => function($value, $context=array()) { + $alphabet = '!"§$%()=<>|^;{}[]'; + $alpha = str_split($alphabet); + foreach($alpha as $char) { + if(strstr($value, $char)) { + return false; + } + } + return true; + }, + + ), + ), + ), + ), + 'surname' => array( + 'required' => true, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'encoding' => 'UTF-8', + 'min' => 1, + 'max' => 45, + ), + ), + array ( + 'name' => 'Callback', + 'options' => array( + 'messages' => array( + \Zend\Validator\Callback::INVALID_VALUE => _('The provided name contains invalid character. These charaters are not allowed:').' !"§$%()=<>|^;{}[]', + ), + 'callback' => function($value, $context=array()) { + $alphabet = '!"§$%()=<>|^;{}[]'; + $alpha = str_split($alphabet); + foreach($alpha as $char) { + if(strstr($value, $char)) { + return false; + } + } + return true; + }, + + ), + ), + ), + ), + 'birthday' => array( + 'required' => true, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'Date', + 'options' => array( + 'format' => 'd.m.Y', + ), + ), + array( + 'name' => 'Callback', + 'options' => array( + 'messages' => array( + \Zend\Validator\Callback::INVALID_VALUE => _('Please choose a valid birthday'), + ), + 'callback' => function($value, $context=array()) { + $min = \DateTime::createFromFormat('d.m.Y', '01.01.1900'); + $max = new \DateTime(); + $birthday = \DateTime::createFromFormat('d.m.Y', $value); + if(!$birthday instanceof \DateTime) { + return false; + } + if($min->getTimestamp() > $birthday->getTimestamp()) { + return false; + } + if($max->getTimestamp() < $birthday->getTimestamp()) { + return false; + } + return true; + }, + ), + ), + ), + ), + 'email' => array( + 'required' => false, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array ( + 'name' => 'EmailAddress', + 'options' => array( + 'messages' => array( + 'emailAddressInvalidFormat' => _('Email address format is not invalid'), + ) + ), + ), + # Check if another user already has this email + array ( + 'name' => 'Callback', + 'options' => array( + 'messages' => array( + \Zend\Validator\Callback::INVALID_VALUE => _('A person with this email address already exists. To make changes to your existing order contact prereg@eja.net or choose another e-mail'), + ), + 'callback' => function($value, $context=array()) { + $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager'); + $user = $em->getRepository('ErsBase\Entity\User') + ->findOneBy(array('email' => $value)); + + # The email address is new -> ok + if (!$user) { + return true; + } + + # The email address belongs to the current user -> ok + if($user->getId() == $context['id']) { + return true; + } + + $auth = $this->getServiceLocator() + ->get('zfcuser_auth_service'); + $identity = $auth->getIdentity(); + if(!empty($identity) && $identity->getEmail() == $user->getEmail()) { + return true; + } + + if(count($user->getRoles()) == 0) { + $now = new \DateTime(); + $diff = $now->getTimestamp()-$user->getUpdated()->getTimestamp(); + if($diff > 3600) { + return true; + } + } + + # The email address belongs to another user -> not ok + return false; + }, + ), + ), + ), + ), + 'newsletter' => array( + 'required' => false, + 'filters' => array( + array('name' => 'Int'), + ), + 'validators' => array( + ), + ), + 'Country_id' => 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..382356e8 --- /dev/null +++ b/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php @@ -0,0 +1,39 @@ +. + */ + +namespace PreReg\View\Helper; + +use Zend\View\Helper\AbstractHelper; +#use Zend\View\HelperPluginManager as ServiceManager; +use Zend\Session\Container; + +class Session extends AbstractHelper { + + #protected $serviceManager; + + /*public function __construct(ServiceManager $serviceManager) { + $this->serviceManager = $serviceManager; + }*/ + + public function __invoke() { + $container = new Container('ers'); + return $container; + } + +} \ 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..0b234f25 --- /dev/null +++ b/module/PreReg/view/partial/currency-chooser.phtml @@ -0,0 +1,62 @@ +
+ +

There is no order to show bank transfer details for

+

Go to products and + choose the items you want.

+ getPaymentType(); + ?> +

translate('Please transfer the amount by SEPA bank transfer to the following account:'); ?>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
translate('Owner'); ?>getOwner(); ?>
translate('IBAN'); ?>niceiban($paymentType->getIban()); ?>
translate('BIC'); ?>getBic(); ?>
translate('Bank'); ?>getBankName(); ?>
translate('Country'); ?>getBankCountry(); ?>
translate('Amount'); ?>currencyFormat($order->getSum(), 'EUR', null, 'de_DE'); ?>
translate('Reason for payment'); ?>getCode()->getValue(); ?>
+ +

translate('Owner address'); ?>

+

getOwnerAddress1())): echo $paymentType->getOwnerAddress1().'
'; endif; + if(!empty($paymentType->getOwnerAddress2())): echo $paymentType->getOwnerAddress2().'
'; endif; + if(!empty($paymentType->getOwnerAddress3())): echo $paymentType->getOwnerAddress3().'
'; endif; + if(!empty($paymentType->getOwnerAddress4())): echo $paymentType->getOwnerAddress4().'
'; endif; + ?>

+ +

translate('Bank address'); ?>

+

getBankAddress1())): echo $paymentType->getBankAddress1().'
'; endif; + if(!empty($paymentType->getBankAddress2())): echo $paymentType->getBankAddress2().'
'; endif; + if(!empty($paymentType->getBankAddress3())): echo $paymentType->getBankAddress3().'
'; endif; + if(!empty($paymentType->getBankAddress4())): echo $paymentType->getBankAddress4().'
'; endif; + ?>

+ +

+ translate('Make sure to fill in this reason for payment %s as the reference for the transfer. Otherwise we won\'t be able to match your payment and your order can\'t be processed.'), $order->getCode()->getValue()); ?> +

+ + +
\ No newline at end of file From d74dfc871655dfa2926b0214e9382e2cc1e16d5d Mon Sep 17 00:00:00 2001 From: Andi Nitsche Date: Sat, 25 Feb 2017 13:04:17 +0100 Subject: [PATCH 2/2] added currency chooser --- config/autoload/bjyauthorize.global.php | 2 +- .../src/ErsBase/Entity/ProductPrice.php | 5 +- .../src/ErsBase/Service/DeadlineService.php | 2 +- .../src/ErsBase/Service/OptionService.php | 24 ++ .../src/ErsBase/Service/OrderService.php | 43 ++- module/PreReg/Module.php | 43 +-- module/PreReg/config/module.config.php | 25 ++ .../PreReg/Controller/ProductController.php | 31 +- .../src/PreReg/Form/CurrencyChooser.php | 296 +----------------- .../PreReg/View/Helper/CurrencyChooser.php | 28 +- .../view/partial/currency-chooser.phtml | 76 +---- module/PreReg/view/pre-reg/order/index.phtml | 6 +- module/PreReg/view/pre-reg/product/add.phtml | 11 +- module/PreReg/view/pre-reg/product/edit.phtml | 7 + .../PreReg/view/pre-reg/product/index.phtml | 22 +- 15 files changed, 212 insertions(+), 409 deletions(-) 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 index 92c767db..c113331a 100644 --- a/module/PreReg/src/PreReg/Form/CurrencyChooser.php +++ b/module/PreReg/src/PreReg/Form/CurrencyChooser.php @@ -14,7 +14,7 @@ use Zend\InputFilter\InputFilterProviderInterface; use Zend\Session\Container; -class Participant extends Form implements InputFilterProviderInterface +class CurrencyChooser extends Form implements InputFilterProviderInterface { protected $em; protected $sm; @@ -37,118 +37,22 @@ public function getServiceLocator() { public function __construct() { - parent::__construct('Participant'); + parent::__construct('currency-chooser'); - $this->setAttribute('method', 'post'); + $this->setAttribute('method', 'post'); $this->add(array( - 'name' => 'id', - 'attributes' => array( - 'type' => 'hidden', - ), - )); - - $this->add(array( - 'name' => 'firstname', - 'type' => 'Zend\Form\Element\Text', - 'attributes' => array( - 'placeholder' => _('First name...'), - 'required' => 'required', - 'class' => 'form-control form-element', - ), - 'options' => array( - 'label' => _('First name'), - 'label_attributes' => array( - 'class' => 'media-object', - ), - ), - )); - - $this->add(array( - 'name' => 'surname', - 'type' => 'Zend\Form\Element\Text', - 'attributes' => array( - 'placeholder' => _('Surname...'), - 'required' => 'required', - 'class' => 'form-control form-element', - ), - 'options' => array( - 'label' => _('Surname'), - 'label_attributes' => array( - 'class' => 'media-object', - ), - ), - )); - - $this->add(array( - 'name' => 'birthday', - #'type' => 'Zend\Form\Element\Date', - #'type' => 'Zend\Form\Element\Text', - 'type' => 'PreReg\Form\Element\DateText', - 'attributes' => array( - 'placeholder' => _('Birthday...'), - 'required' => 'required', - 'class' => 'form-control form-element datepicker', - #'min' => '1900-01-01', - #'max' => 2015-08-09, - #'step' => '1', - ), - 'options' => array( - 'label' => _('Date of birth'), - 'label_attributes' => array( - 'class' => 'media-object', - ), - ), - )); - #$this->get('birthday')->setFormat('Y-m-d'); - $this->get('birthday')->setFormat('d.m.Y'); - - $this->add(array( - 'name' => 'email', - 'type' => 'Zend\Form\Element\Email', - 'attributes' => array( - 'placeholder' => _('Email Address...'), - #'required' => 'required', - 'class' => 'form-control form-element', - ), - 'options' => array( - 'label' => _('Email (optional)'), - 'label_attributes' => array( - 'class' => 'media-object', - ), - ), - )); - - $this->add(array( - 'name' => 'newsletter', - 'type' => 'Zend\Form\Element\Checkbox', - 'attributes' => array( - 'value' => '0', - 'class' => 'form-control form-element', - ), - 'options' => array( - 'label' => _('I\'d like to receive information about the next EJC.'), - 'label_attributes' => array( - 'class' => 'media-object', - ), - 'use_hidden_element' => true, - 'checked_value' => 1, - 'unchecked_value' => 0, - ), - )); - - $this->add(array( - 'name' => 'Country_id', + 'name' => 'currency', 'type' => 'Zend\Form\Element\Select', 'attributes' => array( 'required' => 'required', - 'class' => 'form-control form-element', + 'class' => 'form-control', ), 'options' => array( - 'label' => _('Where are you from?'), + /*'label' => _('Change Currency:'), 'label_attributes' => array( 'class' => 'media-object', - ), + ),*/ ), )); @@ -161,7 +65,7 @@ public function __construct() 'name' => 'submit', 'attributes' => array( 'type' => 'submit', - 'value' => _('Save'), + 'value' => _('Go'), 'id' => 'submitbutton', 'class' => 'btn btn-primary', ), @@ -177,189 +81,7 @@ public function __construct() public function getInputFilterSpecification() { return array( - 'id' => array( - 'required' => false, - 'validators' => array( - ), - ), - 'firstname' => array( - 'required' => true, - 'filters' => array( - array('name' => 'StripTags'), - array('name' => 'StringTrim'), - ), - 'validators' => array( - array( - 'name' => 'StringLength', - 'options' => array( - 'encoding' => 'UTF-8', - 'min' => 1, - 'max' => 45, - ), - ), - array ( - 'name' => 'Callback', - 'options' => array( - 'messages' => array( - \Zend\Validator\Callback::INVALID_VALUE => _('The provided name contains invalid character. These charaters are not allowed:').' !"§$%()=<>|^;{}[]', - ), - 'callback' => function($value, $context=array()) { - $alphabet = '!"§$%()=<>|^;{}[]'; - $alpha = str_split($alphabet); - foreach($alpha as $char) { - if(strstr($value, $char)) { - return false; - } - } - return true; - }, - - ), - ), - ), - ), - 'surname' => array( - 'required' => true, - 'filters' => array( - array('name' => 'StripTags'), - array('name' => 'StringTrim'), - ), - 'validators' => array( - array( - 'name' => 'StringLength', - 'options' => array( - 'encoding' => 'UTF-8', - 'min' => 1, - 'max' => 45, - ), - ), - array ( - 'name' => 'Callback', - 'options' => array( - 'messages' => array( - \Zend\Validator\Callback::INVALID_VALUE => _('The provided name contains invalid character. These charaters are not allowed:').' !"§$%()=<>|^;{}[]', - ), - 'callback' => function($value, $context=array()) { - $alphabet = '!"§$%()=<>|^;{}[]'; - $alpha = str_split($alphabet); - foreach($alpha as $char) { - if(strstr($value, $char)) { - return false; - } - } - return true; - }, - - ), - ), - ), - ), - 'birthday' => array( - 'required' => true, - 'filters' => array( - array('name' => 'StripTags'), - array('name' => 'StringTrim'), - ), - 'validators' => array( - array( - 'name' => 'Date', - 'options' => array( - 'format' => 'd.m.Y', - ), - ), - array( - 'name' => 'Callback', - 'options' => array( - 'messages' => array( - \Zend\Validator\Callback::INVALID_VALUE => _('Please choose a valid birthday'), - ), - 'callback' => function($value, $context=array()) { - $min = \DateTime::createFromFormat('d.m.Y', '01.01.1900'); - $max = new \DateTime(); - $birthday = \DateTime::createFromFormat('d.m.Y', $value); - if(!$birthday instanceof \DateTime) { - return false; - } - if($min->getTimestamp() > $birthday->getTimestamp()) { - return false; - } - if($max->getTimestamp() < $birthday->getTimestamp()) { - return false; - } - return true; - }, - ), - ), - ), - ), - 'email' => array( - 'required' => false, - 'filters' => array( - array('name' => 'StripTags'), - array('name' => 'StringTrim'), - ), - 'validators' => array( - array ( - 'name' => 'EmailAddress', - 'options' => array( - 'messages' => array( - 'emailAddressInvalidFormat' => _('Email address format is not invalid'), - ) - ), - ), - # Check if another user already has this email - array ( - 'name' => 'Callback', - 'options' => array( - 'messages' => array( - \Zend\Validator\Callback::INVALID_VALUE => _('A person with this email address already exists. To make changes to your existing order contact prereg@eja.net or choose another e-mail'), - ), - 'callback' => function($value, $context=array()) { - $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager'); - $user = $em->getRepository('ErsBase\Entity\User') - ->findOneBy(array('email' => $value)); - - # The email address is new -> ok - if (!$user) { - return true; - } - - # The email address belongs to the current user -> ok - if($user->getId() == $context['id']) { - return true; - } - - $auth = $this->getServiceLocator() - ->get('zfcuser_auth_service'); - $identity = $auth->getIdentity(); - if(!empty($identity) && $identity->getEmail() == $user->getEmail()) { - return true; - } - - if(count($user->getRoles()) == 0) { - $now = new \DateTime(); - $diff = $now->getTimestamp()-$user->getUpdated()->getTimestamp(); - if($diff > 3600) { - return true; - } - } - - # The email address belongs to another user -> not ok - return false; - }, - ), - ), - ), - ), - 'newsletter' => array( - 'required' => false, - 'filters' => array( - array('name' => 'Int'), - ), - 'validators' => array( - ), - ), - 'Country_id' => array( + 'currency' => array( 'required' => true, 'filters' => array( array('name' => 'Int'), diff --git a/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php b/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php index 382356e8..c85337f0 100644 --- a/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php +++ b/module/PreReg/src/PreReg/View/Helper/CurrencyChooser.php @@ -22,18 +22,32 @@ use Zend\View\Helper\AbstractHelper; #use Zend\View\HelperPluginManager as ServiceManager; use Zend\Session\Container; +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; -class Session extends AbstractHelper { +class CurrencyChooser extends AbstractHelper implements ServiceLocatorAwareInterface{ - #protected $serviceManager; + protected $sm; - /*public function __construct(ServiceManager $serviceManager) { - $this->serviceManager = $serviceManager; - }*/ + public function __construct() { + #$this->sm = $sm; + } + + public function setServiceLocator(ServiceLocatorInterface $sm) { + $this->sm = $sm; + } + public function getServiceLocator() { + return $this->sm; + } public function __invoke() { - $container = new Container('ers'); - return $container; + 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 index 0b234f25..7bdc2f65 100644 --- a/module/PreReg/view/partial/currency-chooser.phtml +++ b/module/PreReg/view/partial/currency-chooser.phtml @@ -1,62 +1,16 @@ -
- -

There is no order to show bank transfer details for

-

Go to products and - choose the items you want.

- getPaymentType(); - ?> -

translate('Please transfer the amount by SEPA bank transfer to the following account:'); ?>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
translate('Owner'); ?>getOwner(); ?>
translate('IBAN'); ?>niceiban($paymentType->getIban()); ?>
translate('BIC'); ?>getBic(); ?>
translate('Bank'); ?>getBankName(); ?>
translate('Country'); ?>getBankCountry(); ?>
translate('Amount'); ?>currencyFormat($order->getSum(), 'EUR', null, 'de_DE'); ?>
translate('Reason for payment'); ?>getCode()->getValue(); ?>
- -

translate('Owner address'); ?>

-

getOwnerAddress1())): echo $paymentType->getOwnerAddress1().'
'; endif; - if(!empty($paymentType->getOwnerAddress2())): echo $paymentType->getOwnerAddress2().'
'; endif; - if(!empty($paymentType->getOwnerAddress3())): echo $paymentType->getOwnerAddress3().'
'; endif; - if(!empty($paymentType->getOwnerAddress4())): echo $paymentType->getOwnerAddress4().'
'; endif; - ?>

- -

translate('Bank address'); ?>

-

getBankAddress1())): echo $paymentType->getBankAddress1().'
'; endif; - if(!empty($paymentType->getBankAddress2())): echo $paymentType->getBankAddress2().'
'; endif; - if(!empty($paymentType->getBankAddress3())): echo $paymentType->getBankAddress3().'
'; endif; - if(!empty($paymentType->getBankAddress4())): echo $paymentType->getBankAddress4().'
'; endif; - ?>

+setAttribute('action', $this->url('product', array('action' => 'change-currency'))); +$form->prepare(); -

- translate('Make sure to fill in this reason for payment %s as the reference for the transfer. Otherwise we won\'t be able to match your payment and your order can\'t be processed.'), $order->getCode()->getValue()); ?> -

- - -
\ No newline at end of file +echo $this->form()->openTag($form); ?> +
+
session()->currency; ?>
+ formRow($form->get('currency')); ?> + + formSubmit($form->get('submit')); ?> + +
+formHidden($form->get('csrf')); +echo $this->form()->closeTag(); +?> \ No newline at end of file diff --git a/module/PreReg/view/pre-reg/order/index.phtml b/module/PreReg/view/pre-reg/order/index.phtml index 11dacccd..9bf6d5b2 100644 --- a/module/PreReg/view/pre-reg/order/index.phtml +++ b/module/PreReg/view/pre-reg/order/index.phtml @@ -61,13 +61,13 @@ echo $this->navigation() getItems() as $item) : if($item->hasParentItems()) { continue; } - $subtotal += $item->getPrice(); - $sum += $item->getPrice(); + $subtotal += (float) $item->getPrice(); + $sum += (float) $item->getPrice(); ?> diff --git a/module/PreReg/view/pre-reg/product/add.phtml b/module/PreReg/view/pre-reg/product/add.phtml index 76e6d06a..50cdfde5 100644 --- a/module/PreReg/view/pre-reg/product/add.phtml +++ b/module/PreReg/view/pre-reg/product/add.phtml @@ -29,9 +29,9 @@
form; - $form->prepare(); + $form->prepare(); ?> - echo $this->form()->openTag($form); ?> +
@@ -57,11 +57,16 @@
getPriceCount() != 1): ?>

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)); ?>
+ form()->openTag($form); ?>
    @@ -143,10 +148,10 @@
+ form()->closeTag(); ?>
- form()->closeTag(); ?>