Initial commit

This commit is contained in:
2021-03-23 13:54:38 +01:00
commit 82b142ff95
16941 changed files with 2617212 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Controller\Front;
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\Model\AddressQuery;
use Thelia\Model\ModuleQuery;
class BaseFrontController extends BaseController
{
const CONTROLLER_TYPE = 'front';
protected $currentRouter = "router.front";
public function checkAuth()
{
if ($this->getSecurityContext()->hasCustomerUser() === false) {
throw new RedirectException($this->retrieveUrlFromRouteId('customer.login.process'));
}
}
/**
* @return string
*/
public function getControllerType()
{
return self::CONTROLLER_TYPE;
}
protected function checkCartNotEmpty()
{
$cart = $this->getSession()->getSessionCart($this->getDispatcher());
if ($cart===null || $cart->countCartItems() == 0) {
throw new RedirectException($this->retrieveUrlFromRouteId('cart.view'));
}
}
protected function checkValidDelivery()
{
$order = $this->getSession()->getOrder();
if (null === $order
||
null === $order->getChoosenDeliveryAddress()
||
null === $order->getDeliveryModuleId()
||
null === AddressQuery::create()->findPk($order->getChoosenDeliveryAddress())
||
null === ModuleQuery::create()->findPk($order->getDeliveryModuleId())) {
throw new RedirectException($this->retrieveUrlFromRouteId('order.delivery'));
}
}
protected function checkValidInvoice()
{
$order = $this->getSession()->getOrder();
if (null === $order
||
null === $order->getChoosenInvoiceAddress()
||
null === $order->getPaymentModuleId()
||
null === AddressQuery::create()->findPk($order->getChoosenInvoiceAddress())
||
null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
throw new RedirectException($this->retrieveUrlFromRouteId('order.invoice'));
}
}
/**
* @param TemplateDefinition $template the template to process, or null for using the front template
*
* @return ParserInterface the Thelia parser²
*/
protected function getParser($template = null)
{
$parser = $this->container->get("thelia.parser");
// Define the template that should be used
$parser->setTemplateDefinition(
$template ?: $this->getTemplateHelper()->getActiveFrontTemplate(),
$this->useFallbackTemplate
);
return $parser;
}
/**
* Render the given template, and returns the result as an Http Response.
*
* @param string $templateName the complete template name, with extension
* @param array $args the template arguments
* @param int $status http code status
* @return \Thelia\Core\HttpFoundation\Response
*/
protected function render($templateName, $args = array(), $status = 200)
{
return Response::create($this->renderRaw($templateName, $args), $status);
}
/**
* Render the given template, and returns the result as a string.
*
* @param string $templateName the complete template name, with extension
* @param array $args the template arguments
* @param string$templateDir
*
* @return string
*/
protected function renderRaw($templateName, $args = array(), $templateDir = null)
{
// Add the template standard extension
$templateName .= '.html';
// Render the template.
$data = $this->getParser($templateDir)->render($templateName, $args);
return $data;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Controller\Front;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\HttpKernel\Exception\RedirectException;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
/**
* This is the defualt Thelia controller, which is called when no controller was found to process the request.
*
* @author Manuel Raynaud <mraynadu@openstudio.fr>
*/
class DefaultController extends BaseFrontController
{
/**
* This is the default Thelia behaviour if no action is defined.
*
* 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.
*
* Additionaly, if the URL rewriting is enabled, the method will check if a redirect to the pâge rewritten URL should
* be done.
*
* @param \Thelia\Core\HttpFoundation\Request $request
* @throw RedirectException if a redirection to the rewritted URL shoud be done.
*/
public function noAction(Request $request)
{
$view = null;
if (! $view = $request->query->get('view')) {
if ($request->request->has('view')) {
$view = $request->request->get('view');
}
}
if (null !== $view) {
$request->attributes->set('_view', $view);
}
if (null === $view && null === $request->attributes->get("_view")) {
$request->attributes->set("_view", "index");
}
if (ConfigQuery::isRewritingEnable()) {
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 */
throw new RedirectException($rewrittenUrl->rewrittenUrl, 301);
}
}
}
}
public function emptyRoute()
{
return new Response(null, 204);
}
}