Merge branch 'frontend' of github.com:thelia/thelia into frontend
This commit is contained in:
@@ -60,6 +60,27 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
}
|
||||
|
||||
public function updateProfil(CustomerCreateOrUpdateEvent $event)
|
||||
{
|
||||
|
||||
$customer = $event->getCustomer();
|
||||
|
||||
$customer->setDispatcher($this->getDispatcher());
|
||||
|
||||
$customer
|
||||
->setTitleId($event->getTitle())
|
||||
->setFirstname($event->getFirstname())
|
||||
->setLastname($event->getLastname())
|
||||
->setEmail($event->getEmail())
|
||||
->setPassword($event->getPassword())
|
||||
->setReseller($event->getReseller())
|
||||
->setSponsor($event->getSponsor())
|
||||
->setDiscount($event->getDiscount())
|
||||
->save();
|
||||
|
||||
$event->setCustomer($customer);
|
||||
}
|
||||
|
||||
public function delete(CustomerEvent $event)
|
||||
{
|
||||
$customer = $event->getCustomer();
|
||||
@@ -110,11 +131,6 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$this->getSecurityContext()->clearCustomerUser();
|
||||
}
|
||||
|
||||
public function changePassword(ActionEvent $event)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the security context
|
||||
*
|
||||
@@ -150,6 +166,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
return array(
|
||||
TheliaEvents::CUSTOMER_CREATEACCOUNT => array('create', 128),
|
||||
TheliaEvents::CUSTOMER_UPDATEACCOUNT => array('modify', 128),
|
||||
TheliaEvents::CUSTOMER_UPDATEPROFIL => array('updateProfil', 128),
|
||||
TheliaEvents::CUSTOMER_LOGOUT => array('logout', 128),
|
||||
TheliaEvents::CUSTOMER_LOGIN => array('login', 128),
|
||||
TheliaEvents::CUSTOMER_DELETEACCOUNT => array('delete', 128),
|
||||
|
||||
@@ -49,6 +49,11 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
|
||||
->save();
|
||||
}
|
||||
|
||||
public function unsubscribe(NewsletterEvent $event)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
@@ -72,7 +77,8 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::NEWSLETTER_SUBSCRIBE => array('subscribe', 128)
|
||||
TheliaEvents::NEWSLETTER_SUBSCRIBE => array('subscribe', 128),
|
||||
TheliaEvents::NEWSLETTER_UNSUBSCRIBE => array('unsubscribe', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,11 @@ use Thelia\Form\CustomerCreateForm;
|
||||
use Thelia\Form\CustomerLogin;
|
||||
use Thelia\Form\CustomerLostPasswordForm;
|
||||
use Thelia\Form\CustomerPasswordUpdateForm;
|
||||
use Thelia\Form\CustomerUpdateForm;
|
||||
use Thelia\Form\CustomerProfilUpdateForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\NewsletterQuery;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Core\Security\Exception\WrongPasswordException;
|
||||
@@ -131,12 +131,6 @@ class CustomerController extends BaseFrontController
|
||||
}
|
||||
}
|
||||
|
||||
protected function getExistingCustomer($customer_id)
|
||||
{
|
||||
return CustomerQuery::create()
|
||||
->findOneById($customer_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer data. On success, redirect to success_url if exists.
|
||||
* Otherwise, display the same view again.
|
||||
@@ -152,12 +146,13 @@ class CustomerController extends BaseFrontController
|
||||
'firstname' => $customer->getFirstName(),
|
||||
'lastname' => $customer->getLastName(),
|
||||
'email' => $customer->getEmail(),
|
||||
'newsletter' => NewsletterQuery::isSubscribed($customer->getEmail())
|
||||
);
|
||||
|
||||
$customerUpdateForm = new CustomerUpdateForm($this->getRequest(), 'form', $data);
|
||||
$customerProfilUpdateForm = new CustomerProfilUpdateForm($this->getRequest(), 'form', $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($customerUpdateForm);
|
||||
$this->getParserContext()->addForm($customerProfilUpdateForm);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +170,7 @@ class CustomerController extends BaseFrontController
|
||||
|
||||
$customerChangeEvent = $this->createEventInstance($form->getData());
|
||||
$customerChangeEvent->setCustomer($customer);
|
||||
//$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFIL, $customerChangeEvent);
|
||||
|
||||
$this->redirectSuccess($customerPasswordUpdateForm);
|
||||
|
||||
@@ -204,21 +199,27 @@ class CustomerController extends BaseFrontController
|
||||
|
||||
$message = false;
|
||||
|
||||
$customerUpdateForm = new CustomerUpdateForm($this->getRequest());
|
||||
$customerProfilUpdateForm = new CustomerProfilUpdateForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||
|
||||
$form = $this->validateForm($customerUpdateForm, "post");
|
||||
$form = $this->validateForm($customerProfilUpdateForm, "post");
|
||||
|
||||
$customerChangeEvent = $this->createEventInstance($form->getData());
|
||||
$customerChangeEvent->setCustomer($customer);
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFIL, $customerChangeEvent);
|
||||
|
||||
// Newsletter
|
||||
if ($form->get('newsletter')->getData()){
|
||||
//$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $customerChangeEvent);
|
||||
} else {
|
||||
//$this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $customerChangeEvent);
|
||||
}
|
||||
|
||||
$this->processLogin($customerChangeEvent->getCustomer());
|
||||
|
||||
$this->redirectSuccess($customerUpdateForm);
|
||||
$this->redirectSuccess($customerProfilUpdateForm);
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
@@ -229,10 +230,10 @@ class CustomerController extends BaseFrontController
|
||||
if ($message !== false) {
|
||||
Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
|
||||
|
||||
$customerUpdateForm->setErrorMessage($message);
|
||||
$customerProfilUpdateForm->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($customerUpdateForm)
|
||||
->addForm($customerProfilUpdateForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
@@ -329,9 +330,9 @@ class CustomerController extends BaseFrontController
|
||||
private function createEventInstance($data)
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
isset($data["title"])?$data["title"]:null,
|
||||
isset($data["firstname"])?$data["firstname"]:null,
|
||||
isset($data["lastname"])?$data["lastname"]:null,
|
||||
isset($data["address1"])?$data["address1"]:null,
|
||||
isset($data["address2"])?$data["address2"]:null,
|
||||
isset($data["address3"])?$data["address3"]:null,
|
||||
|
||||
@@ -71,6 +71,11 @@ final class TheliaEvents
|
||||
*/
|
||||
const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer";
|
||||
|
||||
/**
|
||||
* sent on customer account update profil
|
||||
*/
|
||||
const CUSTOMER_UPDATEPROFIL = "action.updateProfilCustomer";
|
||||
|
||||
/**
|
||||
* sent on customer removal
|
||||
*/
|
||||
@@ -686,4 +691,9 @@ final class TheliaEvents
|
||||
* sent for subscribing to the newsletter
|
||||
*/
|
||||
const NEWSLETTER_SUBSCRIBE = 'thelia.newsletter.subscribe';
|
||||
|
||||
/**
|
||||
* sent for subscribing to the newsletter
|
||||
*/
|
||||
const NEWSLETTER_UNSUBSCRIBE = 'thelia.newsletter.unsubscribe';
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class CustomerCreateForm extends AddressCreateForm
|
||||
|
||||
public function verifyExistingEmail($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOneByEmail($value);
|
||||
$customer = CustomerQuery::getCustomerByEmail($value);
|
||||
if ($customer) {
|
||||
$context->addViolation("This email already exists.");
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Class CustomerPasswordUpdateForm
|
||||
@@ -79,7 +80,10 @@ class CustomerPasswordUpdateForm extends BaseForm
|
||||
|
||||
public function verifyCurrentPasswordField($value, ExecutionContextInterface $context)
|
||||
{
|
||||
// Check current password
|
||||
// Check if value of the old password match the password of the current user
|
||||
if (!password_verify($value, $this->getRequest()->getSession()->getCustomerUser()->getPassword())) {
|
||||
$context->addViolation("Your current password does not match.");
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyPasswordField($value, ExecutionContextInterface $context)
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
namespace Thelia\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints;
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
@@ -51,6 +53,9 @@ class CustomerProfilUpdateForm extends CustomerCreateForm
|
||||
->remove("city")
|
||||
->remove("zipcode")
|
||||
->remove("country")
|
||||
// Remove Login Information
|
||||
->remove("password")
|
||||
->remove("password_confirm")
|
||||
// Remove Terms & conditions
|
||||
->remove("agreed")
|
||||
|
||||
@@ -64,6 +69,20 @@ class CustomerProfilUpdateForm extends CustomerCreateForm
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function verifyExistingEmail($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$customer = CustomerQuery::getCustomerByEmail($value);
|
||||
// If there is already a customer for this email address and if the customer is different from the current user, do a violation
|
||||
if ($customer && $customer->getId() != $this->getRequest()->getSession()->getCustomerUser()->getId()) {
|
||||
$context->addViolation("This email already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_customer_profil_update";
|
||||
|
||||
@@ -17,4 +17,8 @@ use Thelia\Model\Base\CustomerQuery as BaseCustomerQuery;
|
||||
*/
|
||||
class CustomerQuery extends BaseCustomerQuery {
|
||||
|
||||
public static function getCustomerByEmail($email)
|
||||
{
|
||||
return self::create()->findOneByEmail($email);
|
||||
}
|
||||
} // CustomerQuery
|
||||
|
||||
@@ -17,5 +17,8 @@ use Thelia\Model\Base\NewsletterQuery as BaseNewsletterQuery;
|
||||
*/
|
||||
class NewsletterQuery extends BaseNewsletterQuery
|
||||
{
|
||||
|
||||
public static function isSubscribed($email)
|
||||
{
|
||||
return (null === self::create()->findOneByEmail($email)) ? false : true;
|
||||
}
|
||||
} // NewsletterQuery
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
|
||||
{block name="main-content"}
|
||||
|
||||
{* Used to display the success icon *}
|
||||
{assign var="isPost" value="{$smarty.post|count}"}
|
||||
|
||||
<div class="main">
|
||||
|
||||
<article class="col-main" role="main" aria-labelledby="main-label">
|
||||
@@ -43,12 +40,10 @@
|
||||
<div class="form-group group-password_old {if $error}has-error{elseif $isPost && $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" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
|
||||
<input type="password" name="{$name}" id="{$label_attr.for}" class="form-control" value="{$value}" {if $required} aria-required="true" required{/if}{if $error} autofocus{/if}>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
{elseif $isPost && $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
@@ -58,13 +53,11 @@
|
||||
<div class="form-group group-password {if $error}has-error{elseif $isPost && $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" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
|
||||
<input type="password" name="{$name}" id="{$label_attr.for}" class="form-control" 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 $isPost && $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
{/form_field}
|
||||
@@ -76,8 +69,6 @@
|
||||
{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-->
|
||||
|
||||
@@ -27,12 +27,18 @@
|
||||
$(this).addClass('open');
|
||||
})
|
||||
.on('mouseleave.subnav', '.dropdown', function(){
|
||||
if(!$(this).hasClass('open'))
|
||||
var $this = $(this);
|
||||
|
||||
if(!$this.hasClass('open'))
|
||||
return;
|
||||
|
||||
//This will check if an input child has focus. If no then remove class open
|
||||
if ($(this).find(":input:focus").length == 0){
|
||||
$(this).removeClass('open');
|
||||
if ($this.find(":input:focus").length == 0){
|
||||
$this.removeClass('open');
|
||||
} else {
|
||||
$this.find(":input:focus").one('blur', function(){
|
||||
$this.trigger('mouseleave.subnav');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -69,7 +75,6 @@
|
||||
if($category_products.size() > 0){
|
||||
var $parent = $category_products.parent();
|
||||
|
||||
|
||||
$parent.on('click.view-mode', '[data-toggle=view]', function(){
|
||||
if( ($(this).hasClass('btn-grid') && $parent.hasClass('grid')) || ($(this).hasClass('btn-list') && $parent.hasClass('list')))
|
||||
return;
|
||||
@@ -189,6 +194,25 @@
|
||||
}).filter(':has(:checked)').addClass('active');
|
||||
});
|
||||
|
||||
// Apply validation
|
||||
$('#form-contact, #form-register').validate({
|
||||
highlight: function(element) {
|
||||
$(element).closest('.form-group').addClass('has-error');
|
||||
},
|
||||
unhighlight: function(element) {
|
||||
$(element).closest('.form-group').removeClass('has-error');
|
||||
},
|
||||
errorElement: 'span',
|
||||
errorClass: 'help-block',
|
||||
errorPlacement: function(error, element) {
|
||||
if(element.parent('.input-group').length || element.prop('type') === 'checkbox' || element.prop('type') === 'radio'){
|
||||
error.prepend('<i class="icon-remove"></i> ').insertAfter(element.parent());
|
||||
}else{
|
||||
error.prepend('<i class="icon-remove"></i> ').insertAfter(element);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if($("body").is(".page-product")){
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
{include file="includes/menu.html"}
|
||||
|
||||
{include file="includes/categories-filters.html"}
|
||||
{*include file="includes/categories-filters.html"*}
|
||||
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<div class="form-group group-message {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}" placeholder="{intl l='And your message...'}" rows="6" class="form-control">{$value}</textarea>
|
||||
<textarea name="{$name}" id="{$label_attr.for}" placeholder="{intl l='And your message...'}" rows="6" class="form-control"{if $required} aria-required="true" required{/if}>{$value}</textarea>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<div class="clearfix">
|
||||
{loop type="cart" name="cartloop" position="last"}
|
||||
<table>
|
||||
<tr>
|
||||
@@ -29,10 +30,11 @@
|
||||
</table>
|
||||
{/loop}
|
||||
|
||||
<a href="{navigate to="index"}" role="button" class="btn btn_add_to_cart pull-right"><span>{intl l="View cart"}</span></a>
|
||||
<a href="{navigate to="index"}" role="button" class="btn btn-checkout pull-right"><span>{intl l="Continue Shopping"}</span></a>
|
||||
<a href="{url path="/cart"}" role="button" class="btn btn_add_to_cart pull-right"><span>{intl l="View cart"}</span></a>
|
||||
<button type="button" class="btn btn-checkout pull-right" data-dismiss="modal"><span>{intl l="Continue Shopping"}</span></button>
|
||||
</div>
|
||||
|
||||
{ifloop rel="product_upsell"}
|
||||
{ifloop rel="product_upsell"}
|
||||
<aside id="products-upsell" role="complementary" aria-labelledby="products-upsell-label">
|
||||
<div class="products-heading">
|
||||
<h3 id="products-upsell-label">{intl l="Upsell Products"}</h3>
|
||||
|
||||
@@ -376,6 +376,9 @@ URL: http://www.thelia.net
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
|
||||
|
||||
|
||||
{javascripts file='assets/js/bootstrap/bootstrap.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
@@ -172,7 +172,7 @@
|
||||
{form_field form=$form field='quantity'}
|
||||
<div class="form-group group-qty {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label for="{$label_attr.for}">{$label}</label>
|
||||
<input type="number" name="{$name}" id="{$label_attr.for}" class="form-control" value="{$value|default:1}" min="0" required>
|
||||
<input type="number" name="{$name}" id="{$label_attr.for}" class="form-control" value="{$value|default:1}" min="1" required>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{elseif $value != "" && !$error}
|
||||
|
||||
Reference in New Issue
Block a user