diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml
index e8ea3a9d5..1014d7cad 100755
--- a/core/lib/Thelia/Config/Resources/config.xml
+++ b/core/lib/Thelia/Config/Resources/config.xml
@@ -203,6 +203,7 @@
+
diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php
index 6540f28a4..69ea8553d 100755
--- a/core/lib/Thelia/Controller/Front/BaseFrontController.php
+++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php
@@ -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");
}
}
diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php
index 1bac39b14..f34715894 100755
--- a/core/lib/Thelia/Controller/Front/OrderController.php
+++ b/core/lib/Thelia/Controller/Front/OrderController.php
@@ -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();
diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php
index 24d2c29ee..71b9c3f81 100755
--- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php
+++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php
@@ -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,32 +47,43 @@ 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)
{
- $roles = $this->_explode($this->getParam($params, 'roles'));
- $permissions = $this->_explode($this->getParam($params, 'permissions'));
+ $roles = $this->_explode($this->getParam($params, 'roles'));
+ $permissions = $this->_explode($this->getParam($params, 'permissions'));
- if (! $this->securityContext->isGranted($roles, $permissions)) {
+ if (! $this->securityContext->isGranted($roles, $permissions)) {
- $ex = new AuthenticationException(
- sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
- implode(',', $roles), implode(',', $permissions), $context
- )
- );
+ $ex = new AuthenticationException(
+ sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.",
+ implode(',', $roles), implode(',', $permissions), $context
+ )
+ );
- $loginTpl = $this->getParam($params, 'login_tpl');
+ $loginTpl = $this->getParam($params, 'login_tpl');
- if (null != $loginTpl) {
- $ex->setLoginTemplate($loginTpl);
- }
+ if (null != $loginTpl) {
+ $ex->setLoginTemplate($loginTpl);
+ }
- throw $ex;
- }
+ throw $ex;
+ }
- return '';
+ 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'),
);
}
}
diff --git a/core/lib/Thelia/Exception/OrderException.php b/core/lib/Thelia/Exception/OrderException.php
new file mode 100755
index 000000000..d276f8b59
--- /dev/null
+++ b/core/lib/Thelia/Exception/OrderException.php
@@ -0,0 +1,39 @@
+. */
+/* */
+/*************************************************************************************/
+
+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);
+ }
+}
diff --git a/install/insert.sql b/install/insert.sql
index e50c0bd81..c7287089f 100755
--- a/install/insert.sql
+++ b/install/insert.sql
@@ -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);
diff --git a/install/thelia.sql b/install/thelia.sql
index 3d003091f..dd3247d57 100755
--- a/install/thelia.sql
+++ b/install/thelia.sql
@@ -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`
diff --git a/local/config/schema.xml b/local/config/schema.xml
index 688fc1fa4..9b52fff61 100755
--- a/local/config/schema.xml
+++ b/local/config/schema.xml
@@ -695,6 +695,10 @@
+
+
+
+
diff --git a/templates/default/account.html b/templates/default/account.html
index 94bd58501..cffd5d754 100644
--- a/templates/default/account.html
+++ b/templates/default/account.html
@@ -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"}