Merge branch 'master' into tax

This commit is contained in:
Etienne Roudeix
2013-10-21 19:12:07 +02:00
10 changed files with 399 additions and 2 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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));
}
}

View 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');
}
}
}

View 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;
}
}

View 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';
}
}

View File

@@ -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());
(NULL, 'admin.configuration.template.delete', NOW(), NOW());

View File

@@ -50,6 +50,7 @@
// Form Register
#form-address,
#form-contact,
#form-register {
.panel-body {
.control-label { .make-sm-column(3); }

View File

@@ -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"}
<div class="main">
<article class="col-main" role="main" aria-labelledby="main-label">
<h1 id="main-label" class="page-header">{intl l="Thanks !"}</h1>
<p>{intl l="Thanks for your message, we will contact as soon as possible"}</p>
</article>
</div>
{/block}

View File

@@ -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"}
<div class="main">
<article class="col-main" role="main" aria-labelledby="main-label">
<h1 id="main-label" class="page-header">{intl l="Contact us"}</h1>
{form name="thelia.contact"}
<form id="form-contact" class="form-horizontal" action="{url path="/contact"}" method="post" role="form">
{form_hidden_fields form=$form}
<fieldset id="contact-info" class="panel panel">
<div class="panel-heading">
1. {intl l="Personal Informations"}
</div>
<div class="panel-body">
{form_field form=$form field="firstname"}
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input">
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="John" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
{if $error }
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{assign var="error_focus" value="true"}
{elseif $value != "" && !$error}
<span class="help-block"><i class="icon-ok"></i></span>
{/if}
</div>
</div><!--/.form-group-->
{/form_field}
{form_field form=$form field="lastname"}
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input">
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="John" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
{if $error }
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{assign var="error_focus" value="true"}
{elseif $value != "" && !$error}
<span class="help-block"><i class="icon-ok"></i></span>
{/if}
</div>
</div><!--/.form-group-->
{/form_field}
{form_field form=$form field="email"}
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input">
<input type="email" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="johndoe@domain.com" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
{if $error }
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{assign var="error_focus" value="true"}
{elseif $value != "" && !$error}
<span class="help-block"><i class="icon-ok"></i></span>
{/if}
</div>
</div><!--/.form-group-->
{/form_field}
{form_field form=$form field="subject"}
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input">
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="contact subject" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
{if $error }
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{assign var="error_focus" value="true"}
{elseif $value != "" && !$error}
<span class="help-block"><i class="icon-ok"></i></span>
{/if}
</div>
</div><!--/.form-group-->
{/form_field}
{form_field form=$form field="message"}
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
<div class="control-input">
<textarea name="{$name}" id="{$label_attr.for}" class="form-control">
{$value}
</textarea>
{if $error }
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
{assign var="error_focus" value="true"}
{elseif $value != "" && !$error}
<span class="help-block"><i class="icon-ok"></i></span>
{/if}
</div>
</div><!--/.form-group-->
{/form_field}
<div class="form-group group-btn">
<div class="control-btn">
<button type="submit" class="btn btn-register">{intl l="Send"}</button>
</div>
</div><!--/.form-group-->
</div>
</fieldset>
</form>
{/form}
</article>
</div>
{/block}