Merge branch 'master' into loops
Conflicts: core/lib/Thelia/Core/Template/Loop/Category.php core/lib/Thelia/Core/Template/Loop/FeatureValue.php core/lib/Thelia/Core/Template/Loop/Folder.php core/lib/Thelia/Core/Template/Loop/Product.php core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php install/faker.php
This commit is contained in:
7
core/lib/Thelia/Controller/Front/BaseFrontController.php
Normal file → Executable file
7
core/lib/Thelia/Controller/Front/BaseFrontController.php
Normal file → Executable file
@@ -22,9 +22,8 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
|
||||
use Thelia\Controller\BaseController;
|
||||
|
||||
class BaseFrontController extends BaseController {
|
||||
|
||||
}
|
||||
class BaseFrontController extends BaseController
|
||||
{
|
||||
}
|
||||
|
||||
123
core/lib/Thelia/Controller/Front/CartController.php
Normal file → Executable file
123
core/lib/Thelia/Controller/Front/CartController.php
Normal file → Executable file
@@ -22,33 +22,118 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\CartEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Form\CartAdd;
|
||||
|
||||
class CartController extends BaseFrontController
|
||||
{
|
||||
use \Thelia\Cart\CartTrait;
|
||||
|
||||
public function addArticle()
|
||||
{
|
||||
$cartEvent = $this->getCartEvent();
|
||||
|
||||
$this->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
|
||||
}
|
||||
|
||||
public function modifyArticle()
|
||||
{
|
||||
$cartEvent = $this->getCartEvent();
|
||||
|
||||
$this->dispatch(TheliaEvents::CART_CHANGEARTICLE, $cartEvent);
|
||||
}
|
||||
|
||||
protected function getCartEvent()
|
||||
public function addItem()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$cart = $this->getCart($request);
|
||||
|
||||
return new CartEvent($request, $cart);
|
||||
$cartAdd = $this->getAddCartForm($request);
|
||||
$message = null;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($cartAdd);
|
||||
|
||||
$cartEvent = $this->getCartEvent();
|
||||
$cartEvent->setNewness($form->get("newness")->getData());
|
||||
$cartEvent->setAppend($form->get("append")->getData());
|
||||
$cartEvent->setQuantity($form->get("quantity")->getData());
|
||||
$cartEvent->setProductSaleElementsId($form->get("product_sale_elements_id")->getData());
|
||||
$cartEvent->setProduct($form->get("product")->getData());
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
|
||||
|
||||
$this->redirectSuccess();
|
||||
|
||||
} catch (PropelException $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Failed to add item to cart with message : %s", $e->getMessage()));
|
||||
$message = "Failed to add this article to your cart, please try again";
|
||||
} catch (FormValidationException $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
if ($message) {
|
||||
$cartAdd->setErrorMessage($message);
|
||||
$this->getParserContext()->setErrorForm($cartAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function changeItem()
|
||||
{
|
||||
$cartEvent = $this->getCartEvent();
|
||||
$cartEvent->setCartItem($this->getRequest()->get("cart_item"));
|
||||
$cartEvent->setQuantity($this->getRequest()->get("quantity"));
|
||||
|
||||
try {
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CART_CHANGEITEM, $cartEvent);
|
||||
|
||||
$this->redirectSuccess();
|
||||
} catch(PropelException $e) {
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteItem()
|
||||
{
|
||||
$cartEvent = $this->getCartEvent();
|
||||
$cartEvent->setCartItem($this->getRequest()->get("cart_item"));
|
||||
|
||||
try {
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CART_DELETEITEM, $cartEvent);
|
||||
|
||||
$this->redirectSuccess();
|
||||
} catch (PropelException $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during deleting cartItem with message : %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* use Thelia\Cart\CartTrait for searching current cart or create a new one
|
||||
*
|
||||
* @return CartEvent
|
||||
*/
|
||||
protected function getCartEvent()
|
||||
{
|
||||
$cart = $this->getCart($this->getRequest());
|
||||
|
||||
return new CartEvent($cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the good way to construct the cart form
|
||||
*
|
||||
* @param Request $request
|
||||
* @return CartAdd
|
||||
*/
|
||||
private function getAddCartForm(Request $request)
|
||||
{
|
||||
if ($request->isMethod("post")) {
|
||||
$cartAdd = new CartAdd($request);
|
||||
} else {
|
||||
$cartAdd = new CartAdd(
|
||||
$request,
|
||||
"form",
|
||||
array(),
|
||||
array(
|
||||
'csrf_protection' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $cartAdd;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
136
core/lib/Thelia/Controller/Front/CustomerController.php
Normal file → Executable file
136
core/lib/Thelia/Controller/Front/CustomerController.php
Normal file → Executable file
@@ -22,44 +22,150 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Thelia\Controller\BaseController;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Thelia\Core\Event\CustomerEvent;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\CustomerLoginEvent;
|
||||
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\UsernameNotFoundException;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Form\CustomerCreation;
|
||||
use Thelia\Form\CustomerLogin;
|
||||
use Thelia\Form\CustomerModification;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
class CustomerController extends BaseFrontController {
|
||||
|
||||
class CustomerController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* create a new Customer. Retrieve data in form and dispatch a action.createCustomer event
|
||||
*
|
||||
* if error occurs, message is set in the parserContext
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$customerCreation = new CustomerCreation($request);
|
||||
try {
|
||||
$form = $this->validateForm($customerCreation, "post");
|
||||
|
||||
$event = $this->dispatchEvent("createCustomer");
|
||||
if(null !== $customer = $event->customer) {
|
||||
$this->processLogin($event->customer);
|
||||
$customerCreateEvent = $this->createEventInstance($form->getData());
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $customerCreateEvent);
|
||||
|
||||
$this->processLogin($customerCreateEvent->getCustomer());
|
||||
|
||||
$this->redirectSuccess();
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$customerCreation->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->setErrorForm($customerCreation);
|
||||
} catch (PropelException $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during customer creation process in front context with message : %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function displayCreateAction()
|
||||
public function updateAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$customerModification = new CustomerModification($request);
|
||||
|
||||
try {
|
||||
|
||||
$customer = $this->getSecurityContext(SecurityContext::CONTEXT_FRONT_OFFICE)->getUser();
|
||||
|
||||
$form = $this->validateForm($customerModification, "post");
|
||||
|
||||
$customerChangeEvent = $this->createEventInstance($form->getData());
|
||||
$customerChangeEvent->setCustomer($customer);
|
||||
|
||||
$this->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $customerChangeEvent);
|
||||
|
||||
$this->processLogin($customerChangeEvent->getCustomer());
|
||||
|
||||
$this->redirectSuccess();
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$customerModification->setErrorMessage($e->getMessage());
|
||||
$this->getParserContext()->setErrorForm($customerModification);
|
||||
} catch (PropelException $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during updating customer in front context with message : %s", $e->getMessage()));
|
||||
$this->getParserContext()->setGeneralError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform user login. On a successful login, the user is redirected to the URL
|
||||
* found in the success_url form parameter, or / if none was found.
|
||||
*
|
||||
* If login is not successfull, the same view is dispolyed again.
|
||||
*
|
||||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
$event = $this->dispatchEvent("loginCustomer");
|
||||
$request = $this->getRequest();
|
||||
|
||||
$customerEvent = new CustomerEvent($event->getCustomer());
|
||||
$customerLoginForm = new CustomerLogin($request);
|
||||
|
||||
$this->processLogin($event->getCustomer(), $customerEvent, true);
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
|
||||
try {
|
||||
$customer = $authenticator->getAuthentifiedUser();
|
||||
|
||||
$customerLoginEvent = new CustomerLoginEvent($customer);
|
||||
|
||||
$this->processLogin($customer, $customerLoginEvent);
|
||||
|
||||
$this->redirectSuccess();
|
||||
} catch (ValidatorException $e) {
|
||||
|
||||
} catch(UsernameNotFoundException $e) {
|
||||
|
||||
} catch(AuthenticationException $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function processLogin(Customer $customer,$event = null, $sendLogin = false)
|
||||
public function processLogin(Customer $customer,$event = null)
|
||||
{
|
||||
$this->getSecurityContext(SecurityContext::CONTEXT_FRONT_OFFICE)->setUser($customer);
|
||||
|
||||
if($sendLogin) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
|
||||
if($event) $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param $data
|
||||
* @return CustomerCreateOrUpdateEvent
|
||||
*/
|
||||
private function createEventInstance($data)
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
$data["address1"],
|
||||
$data["address2"],
|
||||
$data["address3"],
|
||||
$data["phone"],
|
||||
$data["cellphone"],
|
||||
$data["zipcode"],
|
||||
$data["city"],
|
||||
$data["country"],
|
||||
isset($data["email"])?$data["email"]:null,
|
||||
isset($data["password"]) ? $data["password"]:null,
|
||||
$this->getRequest()->getSession()->getLang(),
|
||||
isset($data["reseller"])?$data["reseller"]:null,
|
||||
isset($data["sponsor"])?$data["sponsor"]:null,
|
||||
isset($data["discount"])?$data["discount"]:nullsch
|
||||
);
|
||||
|
||||
return $customerCreateEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
55
core/lib/Thelia/Controller/Front/DefaultController.php
Executable file
55
core/lib/Thelia/Controller/Front/DefaultController.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?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 Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
*
|
||||
* Must be the last controller call. It fixes default values
|
||||
*
|
||||
* @author Manuel Raynaud <mraynadu@openstudio.fr>
|
||||
*/
|
||||
|
||||
class DefaultController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* set the default value for thelia
|
||||
*
|
||||
* In this case there is no action so we have to verify if some needed params are not missing
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*/
|
||||
public function noAction(Request $request)
|
||||
{
|
||||
if (! $view = $request->query->get('view')) {
|
||||
$view = "index";
|
||||
if ($request->request->has('view')) {
|
||||
$view = $request->request->get('view');
|
||||
}
|
||||
}
|
||||
|
||||
$request->attributes->set('_view', $view);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user