diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 2caf016e2..4305851b1 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -145,6 +145,8 @@
+ + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 351ba2ab4..74cf23db8 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -164,4 +164,23 @@ + + Thelia\Controller\Front\Mail::test + + + + Thelia\Controller\Front\DefaultController::noAction + contact + + + + Thelia\Controller\Front\ContactController::sendAction + contact + + + + Thelia\Controller\Front\DefaultController::noAction + contact-success + + diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index e9f359411..548ef9681 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -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)); + } } diff --git a/core/lib/Thelia/Controller/Front/ContactController.php b/core/lib/Thelia/Controller/Front/ContactController.php new file mode 100644 index 000000000..83bd2588e --- /dev/null +++ b/core/lib/Thelia/Controller/Front/ContactController.php @@ -0,0 +1,73 @@ +. */ +/* */ +/*************************************************************************************/ + +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 + */ +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'); + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/Mail.php b/core/lib/Thelia/Controller/Front/Mail.php new file mode 100644 index 000000000..dfaf2d4fa --- /dev/null +++ b/core/lib/Thelia/Controller/Front/Mail.php @@ -0,0 +1,49 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Front; + + +/** + * Class Mail + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ +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; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/ContactForm.php b/core/lib/Thelia/Form/ContactForm.php new file mode 100644 index 000000000..097e651da --- /dev/null +++ b/core/lib/Thelia/Form/ContactForm.php @@ -0,0 +1,119 @@ +. */ +/* */ +/*************************************************************************************/ + +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 + */ +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'; + } +} \ No newline at end of file diff --git a/install/insert.sql b/install/insert.sql index 17707c299..7a5b34ca9 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -28,7 +28,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat ('thelia_customer_remember_me_cookie_name', 'tcrmcn', 0, 0, NOW(), NOW()), ('thelia_customer_remember_me_cookie_expiration', 31536000, 0, 0, NOW(), NOW()), ('session_config.handlers', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler', 0, 0, NOW(), NOW()), -('company_name','', 0, 0, NOW(), NOW()) +('company_name','', 0, 0, NOW(), NOW()), +('contact_email','', 0, 0, NOW(), NOW()) ; @@ -1288,4 +1289,4 @@ INSERT INTO resource (`id`, `code`, `created_at`, `updated_at`) VALUES (NULL, 'admin.configuration.template.view', NOW(), NOW()), (NULL, 'admin.configuration.template.create', NOW(), NOW()), (NULL, 'admin.configuration.template.update', NOW(), NOW()), -(NULL, 'admin.configuration.template.delete', NOW(), NOW()); \ No newline at end of file +(NULL, 'admin.configuration.template.delete', NOW(), NOW()); diff --git a/templates/default/assets/less/thelia/forms.less b/templates/default/assets/less/thelia/forms.less index c8e8a3dad..d39d64ea1 100755 --- a/templates/default/assets/less/thelia/forms.less +++ b/templates/default/assets/less/thelia/forms.less @@ -50,6 +50,7 @@ // Form Register #form-address, +#form-contact, #form-register { .panel-body { .control-label { .make-sm-column(3); } diff --git a/templates/default/contact-success.html b/templates/default/contact-success.html new file mode 100644 index 000000000..59a79974e --- /dev/null +++ b/templates/default/contact-success.html @@ -0,0 +1,15 @@ +{extends file="layout.tpl"} + +{* Breadcrumb *} +{block name='no-return-functions' append} + {$breadcrumbs = [['title' => {intl l="Thanks !"}, 'url'=>{url path="/contact/success"}]]} +{/block} + +{block name="main-content"} +
+
+

{intl l="Thanks !"}

+

{intl l="Thanks for your message, we will contact as soon as possible"}

+
+
+{/block} \ No newline at end of file diff --git a/templates/default/contact.html b/templates/default/contact.html new file mode 100644 index 000000000..2a9458368 --- /dev/null +++ b/templates/default/contact.html @@ -0,0 +1,105 @@ +{extends file="layout.tpl"} + +{* Breadcrumb *} +{block name='no-return-functions' append} + {$breadcrumbs = [['title' => {intl l="Contact us"}, 'url'=>{url path="/contact"}]]} +{/block} + +{block name="main-content"} +
+
+

{intl l="Contact us"}

+ + {form name="thelia.contact"} + + {form_hidden_fields form=$form} +
+
+ 1. {intl l="Personal Informations"} +
+
+ {form_field form=$form field="firstname"} +
+ +
+ + {if $error } + {$message} + {assign var="error_focus" value="true"} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + {form_field form=$form field="lastname"} +
+ +
+ + {if $error } + {$message} + {assign var="error_focus" value="true"} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + {form_field form=$form field="email"} +
+ +
+ + {if $error } + {$message} + {assign var="error_focus" value="true"} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + {form_field form=$form field="subject"} +
+ +
+ + {if $error } + {$message} + {assign var="error_focus" value="true"} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + {form_field form=$form field="message"} +
+ +
+ + {if $error } + {$message} + {assign var="error_focus" value="true"} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + +
+
+ +
+
+
+
+ + {/form} +
+
+{/block} \ No newline at end of file