no-return-functions block
This commit is contained in:
@@ -203,6 +203,7 @@
|
||||
|
||||
<service id="smarty.plugin.security" class="Thelia\Core\Template\Smarty\Plugins\Security" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
<argument type="service" id="request" />
|
||||
<argument type="service" id="thelia.securityContext" />
|
||||
</service>
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ class BaseFrontController extends BaseController
|
||||
|
||||
protected function checkCartNotEmpty()
|
||||
{
|
||||
if($this->getSession()->getCart()->countCartItems() == 0) {
|
||||
$cart = $this->getSession()->getCart();
|
||||
if($cart===null || $cart->countCartItems() == 0) {
|
||||
$this->redirectToRoute("cart.view");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ use Thelia\Core\Event\TheliaEvents;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Form\OrderDelivery;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\Base\AddressQuery;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\AreaDeliveryModuleQuery;
|
||||
use Thelia\Model\Order;
|
||||
|
||||
/**
|
||||
@@ -53,9 +54,6 @@ class OrderController extends BaseFrontController
|
||||
|
||||
$orderDelivery = new OrderDelivery($this->getRequest());
|
||||
|
||||
$x = $this->getRequest();
|
||||
$y = $_POST;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($orderDelivery, "post");
|
||||
|
||||
@@ -69,7 +67,12 @@ class OrderController extends BaseFrontController
|
||||
}
|
||||
|
||||
/* check that the delivery module fetch the delivery address area */
|
||||
|
||||
if(AreaDeliveryModuleQuery::create()
|
||||
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
|
||||
->filterByDeliveryModuleId()
|
||||
->count() == 0) {
|
||||
throw new \Exception("PUKE");
|
||||
}
|
||||
|
||||
|
||||
$orderEvent = $this->getOrderEvent();
|
||||
|
||||
@@ -23,18 +23,22 @@
|
||||
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Exception\OrderException;
|
||||
|
||||
class Security extends AbstractSmartyPlugin
|
||||
{
|
||||
protected $request;
|
||||
private $securityContext;
|
||||
|
||||
public function __construct(SecurityContext $securityContext)
|
||||
public function __construct(Request $request, SecurityContext $securityContext)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,6 +47,7 @@ class Security extends AbstractSmartyPlugin
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string no text is returned.
|
||||
* @throws \Thelia\Core\Security\Exception\AuthenticationException
|
||||
*/
|
||||
public function checkAuthFunction($params, &$smarty)
|
||||
{
|
||||
@@ -69,6 +74,16 @@ class Security extends AbstractSmartyPlugin
|
||||
return '';
|
||||
}
|
||||
|
||||
public function checkCartNotEmptyFunction($params, &$smarty)
|
||||
{
|
||||
$cart = $this->request->getSession()->getCart();
|
||||
if($cart===null || $cart->countCartItems() == 0) {
|
||||
throw new OrderException('Cart must not be empty', OrderException::CART_EMPTY);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the various smarty plugins handled by this class
|
||||
*
|
||||
@@ -77,7 +92,8 @@ class Security extends AbstractSmartyPlugin
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction')
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction'),
|
||||
new SmartyPluginDescriptor('function', 'check_cart_not_empty', $this, 'checkCartNotEmptyFunction'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
39
core/lib/Thelia/Exception/OrderException.php
Executable file
39
core/lib/Thelia/Exception/OrderException.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?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\Exception;
|
||||
|
||||
class OrderException extends \RuntimeException
|
||||
{
|
||||
const UNKNOWN_EXCEPTION = 0;
|
||||
|
||||
const CART_EMPTY = 100;
|
||||
|
||||
public function __construct($message, $code = null, $previous = null)
|
||||
{
|
||||
if ($code === null) {
|
||||
$code = self::UNKNOWN_EXCEPTION;
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namesp
|
||||
(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()),
|
||||
(2, 'Colissimo', 2, 1, 1, 'Colissimo\\Colissimo', NOW(), NOW());
|
||||
|
||||
INSERT INTO `thelia_2`.`module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES
|
||||
INSERT INTO `module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES
|
||||
('2', 'en_US', '72h delivery', NULL, NULL, NULL),
|
||||
('2', 'fr_FR', 'Livraison par colissimo en 72h', NULL, NULL, NULL);
|
||||
|
||||
|
||||
@@ -893,6 +893,7 @@ CREATE TABLE `area_delivery_module`
|
||||
`created_at` DATETIME,
|
||||
`updated_at` DATETIME,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `delivery_module_id_area_id_UNIQUE` (`area_id`, `delivery_module_id`),
|
||||
INDEX `idx_area_delivery_module_area_id` (`area_id`),
|
||||
INDEX `idx_area_delivery_module_delivery_module_id` (`delivery_module_id`),
|
||||
CONSTRAINT `fk_area_delivery_module_area_id`
|
||||
|
||||
@@ -695,6 +695,10 @@
|
||||
<index name="idx_area_delivery_module_delivery_module_id">
|
||||
<index-column name="delivery_module_id" />
|
||||
</index>
|
||||
<unique name="delivery_module_id_area_id_UNIQUE">
|
||||
<unique-column name="area_id" />
|
||||
<unique-column name="delivery_module_id" />
|
||||
</unique>
|
||||
<behavior name="timestampable" />
|
||||
</table>
|
||||
<table name="group" namespace="Thelia\Model">
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="no-return-functions"}
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{/block}
|
||||
|
||||
{block name="breadcrumb"}
|
||||
<nav class="nav-breadcrumb" role="navigation" aria-labelledby="breadcrumb-label">
|
||||
<strong id="breadcrumb-label">{intl l="You are here"}: </strong>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="no-return-functions"}
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{/block}
|
||||
|
||||
{block name="breadcrumb"}
|
||||
<nav class="nav-breadcrumb" role="navigation" aria-labelledby="breadcrumb-label">
|
||||
<strong id="breadcrumb-label">{intl l="You are here"}: </strong>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="no-return-functions"}
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{/block}
|
||||
|
||||
{block name="breadcrumb"}
|
||||
<nav class="nav-breadcrumb" role="navigation" aria-labelledby="breadcrumb-label">
|
||||
<strong id="breadcrumb-label">You are here: </strong>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{block name="no-return-functions"}{/block}
|
||||
<!doctype html>
|
||||
<!--
|
||||
______ __ __ ______ __ __ ______
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="no-return-functions"}
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{check_cart_not_empty}
|
||||
{/block}
|
||||
|
||||
{block name="breadcrumb"}
|
||||
<nav class="nav-breadcrumb" role="navigation" aria-labelledby="breadcrumb-label">
|
||||
<strong id="breadcrumb-label">You are here: </strong>
|
||||
|
||||
Reference in New Issue
Block a user