Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -22,15 +22,17 @@
/*************************************************************************************/
namespace Front\Controller;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Form\ContactForm;
use Thelia\Form\Definition\FrontForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
/**
* Class ContactController
* @package Thelia\Controller\Front
* @author Manuel Raynaud <mraynaud@openstudio.fr>
* @author Manuel Raynaud <manu@raynaud.io>
*/
class ContactController extends BaseFrontController
{
@@ -39,36 +41,44 @@ class ContactController extends BaseFrontController
*/
public function sendAction()
{
$error_message = false;
$contactForm = new ContactForm($this->getRequest());
$contactForm = $this->createForm(FrontForm::CONTACT);
try {
$form = $this->validateForm($contactForm);
$message = \Swift_Message::newInstance($form->get('subject')->getData())
->addFrom(ConfigQuery::read("store_email"), $form->get('name')->getData())
->addReplyTo($form->get('email')->getData(), $form->get('name')->getData())
->addTo(ConfigQuery::read('store_email'), ConfigQuery::read('store_name'))
->setBody($form->get('message')->getData())
;
$this->getMailer()->send($message);
$this->getMailer()->sendSimpleEmailMessage(
[ ConfigQuery::getStoreEmail() => $form->get('name')->getData() ],
[ ConfigQuery::getStoreEmail() => ConfigQuery::getStoreName() ],
$form->get('subject')->getData(),
'',
$form->get('message')->getData(),
[],
[],
[ $form->get('email')->getData() => $form->get('name')->getData() ]
);
if ($contactForm->hasSuccessUrl()) {
return $this->generateSuccessRedirect($contactForm);
}
return $this->generateRedirectFromRoute('contact.success');
} catch (FormValidationException $e) {
$error_message = $e->getMessage();
}
if ($error_message !== false) {
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during sending contact mail : %s', $error_message));
$contactForm->setErrorMessage($error_message);
$this->getParserContext()
->addForm($contactForm)
->setGeneralError($error_message)
;
} else {
$this->redirectToRoute('contact.success');
Tlog::getInstance()->error(sprintf('Error during sending contact mail : %s', $error_message));
$contactForm->setErrorMessage($error_message);
$this->getParserContext()
->addForm($contactForm)
->setGeneralError($error_message)
;
// Redirect to error URL if defined
if ($contactForm->hasErrorUrl()) {
return $this->generateErrorRedirect($contactForm);
}
}
}