Merge branch 'master' into tax
This commit is contained in:
@@ -145,6 +145,8 @@
|
||||
|
||||
<form name="thelia.shopping_zone_area" class="Thelia\Form\ShippingZone\ShippingZoneAddArea"/>
|
||||
<form name="thelia.shopping_zone_remove_area" class="Thelia\Form\ShippingZone\ShippingZoneRemoveArea"/>
|
||||
|
||||
<form name="thelia.contact" class="Thelia\Form\ContactForm"/>
|
||||
</forms>
|
||||
|
||||
|
||||
|
||||
@@ -164,4 +164,23 @@
|
||||
</route>
|
||||
<!-- end order management process -->
|
||||
|
||||
<route id="mail.test" path="/mail/test">
|
||||
<default key="_controller">Thelia\Controller\Front\Mail::test</default>
|
||||
</route>
|
||||
|
||||
<route id="contact.display" path="/contact" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">contact</default>
|
||||
</route>
|
||||
|
||||
<route id="contact.send" path="/contact" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\ContactController::sendAction</default>
|
||||
<default key="_view">contact</default>
|
||||
</route>
|
||||
|
||||
<route id="contact.success" path="/contact/success">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">contact-success</default>
|
||||
</route>
|
||||
|
||||
</routes>
|
||||
|
||||
@@ -303,4 +303,17 @@ class BaseController extends ContainerAware
|
||||
|
||||
return $mailer->getSwiftMailer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ParserInterface instance parser
|
||||
*/
|
||||
protected function getParser()
|
||||
{
|
||||
return $this->container->get("thelia.parser");
|
||||
}
|
||||
|
||||
protected function render($inline)
|
||||
{
|
||||
return $this->getParser()->fetch(sprintf("string:%s", $inline));
|
||||
}
|
||||
}
|
||||
|
||||
73
core/lib/Thelia/Controller/Front/ContactController.php
Normal file
73
core/lib/Thelia/Controller/Front/ContactController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
use Thelia\Form\ContactForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContactController
|
||||
* @package Thelia\Controller\Front
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ContactController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* send contact message
|
||||
*/
|
||||
public function sendAction()
|
||||
{
|
||||
$error_message = false;
|
||||
$contactForm = new ContactForm($this->getRequest());
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($contactForm);
|
||||
|
||||
$message = \Swift_Message::newInstance($form->get('subject')->getData())
|
||||
->addFrom($form->get('email')->getData(), $form->get('firstname')->getData().' '.$form->get('lastname')->getData())
|
||||
->addTo(ConfigQuery::read('contact_email'), ConfigQuery::read('company_name'))
|
||||
->setBody($form->get('message')->getData())
|
||||
;
|
||||
|
||||
$this->getMailer()->send($message);
|
||||
|
||||
} catch(FormValidationException $e) {
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
|
||||
if ($error_message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer creation process : %s", $error_message));
|
||||
|
||||
$contactForm->setErrorMessage($error_message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($contactForm)
|
||||
->setGeneralError($error_message)
|
||||
;
|
||||
} else {
|
||||
$this->redirectToRoute('contact.success');
|
||||
}
|
||||
}
|
||||
}
|
||||
49
core/lib/Thelia/Controller/Front/Mail.php
Normal file
49
core/lib/Thelia/Controller/Front/Mail.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
|
||||
/**
|
||||
* Class Mail
|
||||
* @package Thelia\Controller\Front
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Mail extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* This is a demo how to send a mail using swiftmailer + smarty
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
$message = \Swift_Message::newInstance('Wonderful Subject')
|
||||
->setFrom(array('john@doe.com' => 'John Doe'))
|
||||
->setTo(array('mraynaud@openstudio.fr' => 'name'))
|
||||
->setBody($this->render('Here is the message itself'))
|
||||
;
|
||||
|
||||
$this->getMailer()->send($message);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
119
core/lib/Thelia/Form/ContactForm.php
Normal file
119
core/lib/Thelia/Form/ContactForm.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContactForm
|
||||
* @package Thelia\Form
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ContactForm extends BaseForm
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add('firstname', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('firstname'),
|
||||
'label_attr' => array(
|
||||
'for' => 'firstname_contact'
|
||||
)
|
||||
))
|
||||
->add('lastname', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('lastname'),
|
||||
'label_attr' => array(
|
||||
'for' => 'lastname_contact'
|
||||
)
|
||||
))
|
||||
->add('email', 'email', array(
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
new Email()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('email'),
|
||||
'label_attr' => array(
|
||||
'for' => 'email_contact'
|
||||
)
|
||||
))
|
||||
->add('subject', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('subject'),
|
||||
'label_attr' => array(
|
||||
'for' => 'subject_contact'
|
||||
)
|
||||
))
|
||||
->add('message', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('message'),
|
||||
'label_attr' => array(
|
||||
'for' => 'message_contact'
|
||||
)
|
||||
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_contact';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user