Inital commit
This commit is contained in:
@@ -12,67 +12,40 @@
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Controller\BaseController;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpKernel\Exception\RedirectException;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class BaseFrontController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Return the route path defined for the givent route ID
|
||||
*
|
||||
* @param string $routeId a route ID, as defines in Config/Resources/routing/front.xml
|
||||
*
|
||||
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
|
||||
*/
|
||||
const CONTROLLER_TYPE = 'front';
|
||||
|
||||
/**
|
||||
* Return the route path defined for the givent route ID
|
||||
*
|
||||
* @param string $routeId the route ID, as found in Config/Resources/routing/admin.xml
|
||||
* @param array $parameters the Route parameters, as a var/value pair array
|
||||
* @param bool $referenceType Router::ABSOLUTE_PATH or Router::ABSOLUTE_URL
|
||||
*
|
||||
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
|
||||
*
|
||||
* @return string the route path
|
||||
*/
|
||||
protected function getRoute($routeId, $parameters = array(), $referenceType = Router::ABSOLUTE_PATH)
|
||||
{
|
||||
return $this->getRouteFromRouter('router.front', $routeId, $parameters, $referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to a specific route.
|
||||
*
|
||||
* @param string $routeId the route ID, as found in Config/Resources/routing/admin.xml
|
||||
* @param array $urlParameters the URL parameters, as a var/value pair array
|
||||
* @param array $routeParameters the Route parameters, as a var/value pair array
|
||||
* @param bool $referenceType Router::ABSOLUTE_PATH or Router::ABSOLUTE_URL
|
||||
*/
|
||||
public function redirectToRoute($routeId, array $urlParameters = [], array $routeParameters = [], $referenceType = Router::ABSOLUTE_PATH)
|
||||
{
|
||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, $routeParameters, $referenceType), $urlParameters));
|
||||
}
|
||||
protected $currentRouter = "router.front";
|
||||
|
||||
public function checkAuth()
|
||||
{
|
||||
if ($this->getSecurityContext()->hasCustomerUser() === false) {
|
||||
$this->redirectToRoute('customer.login.process');
|
||||
throw new RedirectException($this->retrieveUrlFromRouteId('customer.login.process'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getControllerType()
|
||||
{
|
||||
return self::CONTROLLER_TYPE;
|
||||
}
|
||||
|
||||
protected function checkCartNotEmpty()
|
||||
{
|
||||
$cart = $this->getSession()->getCart();
|
||||
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
|
||||
if ($cart===null || $cart->countCartItems() == 0) {
|
||||
$this->redirectToRoute('cart.view');
|
||||
throw new RedirectException($this->retrieveUrlFromRouteId('cart.view'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +61,7 @@ class BaseFrontController extends BaseController
|
||||
null === AddressQuery::create()->findPk($order->getChoosenDeliveryAddress())
|
||||
||
|
||||
null === ModuleQuery::create()->findPk($order->getDeliveryModuleId())) {
|
||||
$this->redirectToRoute("order.delivery");
|
||||
throw new RedirectException($this->retrieveUrlFromRouteId('order.delivery'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +77,7 @@ class BaseFrontController extends BaseController
|
||||
null === AddressQuery::create()->findPk($order->getChoosenInvoiceAddress())
|
||||
||
|
||||
null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
|
||||
$this->redirectToRoute("order.invoice");
|
||||
throw new RedirectException($this->retrieveUrlFromRouteId('order.invoice'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +91,10 @@ class BaseFrontController extends BaseController
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template that should be used
|
||||
$parser->setTemplateDefinition($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate());
|
||||
$parser->setTemplateDefinition(
|
||||
$template ?: $this->getTemplateHelper()->getActiveFrontTemplate(),
|
||||
$this->useFallbackTemplate
|
||||
);
|
||||
|
||||
return $parser;
|
||||
}
|
||||
@@ -147,25 +123,12 @@ class BaseFrontController extends BaseController
|
||||
*/
|
||||
protected function renderRaw($templateName, $args = array(), $templateDir = null)
|
||||
{
|
||||
|
||||
// Add the template standard extension
|
||||
$templateName .= '.html';
|
||||
|
||||
$session = $this->getSession();
|
||||
|
||||
// Prepare common template variables
|
||||
$args = array_merge($args, array(
|
||||
'locale' => $session->getLang()->getLocale(),
|
||||
'lang_code' => $session->getLang()->getCode(),
|
||||
'lang_id' => $session->getLang()->getId(),
|
||||
'current_url' => $this->getRequest()->getUri()
|
||||
));
|
||||
|
||||
// Render the template.
|
||||
|
||||
$data = $this->getParser($templateDir)->render($templateName, $args);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpKernel\Exception\RedirectException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* Must be the last controller call. It fixes default values
|
||||
* This is the defualt Thelia controller, which is called when no controller was found to process the request.
|
||||
*
|
||||
* @author Manuel Raynaud <mraynadu@openstudio.fr>
|
||||
*/
|
||||
@@ -27,12 +27,17 @@ use Thelia\Tools\URL;
|
||||
class DefaultController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* This is the default Thelia behaviour if no action is defined.
|
||||
*
|
||||
* set the default value for thelia
|
||||
* If the request contains a 'view' parameter, this view will be displayed.
|
||||
* If the request contains a '_view' attribute (set in the route definition, for example), this view will be displayed.
|
||||
* Otherwise, we will use the "index" view.
|
||||
*
|
||||
* In this case there is no action so we have to verify if some needed params are not missing
|
||||
* Additionaly, if the URL rewriting is enabled, the method will check if a redirect to the pâge rewritten URL should
|
||||
* be done.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \Thelia\Core\HttpFoundation\Request $request
|
||||
* @throw RedirectException if a redirection to the rewritted URL shoud be done.
|
||||
*/
|
||||
public function noAction(Request $request)
|
||||
{
|
||||
@@ -55,11 +60,17 @@ class DefaultController extends BaseFrontController
|
||||
if ($request->attributes->get('_rewritten', false) === false) {
|
||||
/* Does the query GET parameters match a rewritten URL ? */
|
||||
$rewrittenUrl = URL::getInstance()->retrieveCurrent($request);
|
||||
|
||||
if ($rewrittenUrl->rewrittenUrl !== null) {
|
||||
/* 301 redirection to rewritten URL */
|
||||
$this->redirect($rewrittenUrl->rewrittenUrl, 301);
|
||||
throw new RedirectException($rewrittenUrl->rewrittenUrl, 301);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function emptyRoute()
|
||||
{
|
||||
return new Response(null, 204);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user