empty cart or delivery exception
This commit is contained in:
@@ -112,12 +112,12 @@
|
||||
<default key="_view">cart</default>
|
||||
</route>
|
||||
|
||||
<route id="order.delivery" path="/order/delivery" methods="post">
|
||||
<route id="order.delivery.process" path="/order/delivery" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\OrderController::deliver</default>
|
||||
<default key="_view">order_delivery</default>
|
||||
</route>
|
||||
|
||||
<route id="order.delivery.process" path="/order/delivery">
|
||||
<route id="order.delivery" path="/order/delivery">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">order_delivery</default>
|
||||
</route>
|
||||
|
||||
@@ -69,9 +69,9 @@ class OrderController extends BaseFrontController
|
||||
/* check that the delivery module fetch the delivery address area */
|
||||
if(AreaDeliveryModuleQuery::create()
|
||||
->filterByAreaId($deliveryAddress->getCountry()->getAreaId())
|
||||
->filterByDeliveryModuleId()
|
||||
->filterByDeliveryModuleId($deliveryModuleId)
|
||||
->count() == 0) {
|
||||
throw new \Exception("PUKE");
|
||||
throw new \Exception("Delivery module cannot be use with selected delivery address");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@ use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
use Thelia\Exception\OrderException;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
@@ -87,6 +89,19 @@ class ViewListener implements EventSubscriberInterface
|
||||
|
||||
// Redirect to the login template
|
||||
Redirect::exec($this->container->get('thelia.url.manager')->viewUrl($ex->getLoginTemplate()));
|
||||
} catch (OrderException $e) {
|
||||
switch($e->getCode()) {
|
||||
case OrderException::CART_EMPTY:
|
||||
// Redirect to the cart template
|
||||
Redirect::exec($this->container->get('router.chainRequest')->generate($e->cartRoute, $e->arguments, Router::ABSOLUTE_URL));
|
||||
break;
|
||||
case OrderException::UNDEFINED_DELIVERY:
|
||||
// Redirect to the delivery choice template
|
||||
Redirect::exec($this->container->get('router.chainRequest')->generate($e->orderDeliveryRoute, $e->arguments, Router::ABSOLUTE_URL));
|
||||
break;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -218,6 +218,9 @@ class Session extends BaseSession
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Order
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->get("thelia.order");
|
||||
|
||||
@@ -128,7 +128,7 @@ class RewritingRouter implements RouterInterface, RequestMatcherInterface
|
||||
*/
|
||||
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
// TODO: Implement generate() method.
|
||||
throw new RouteNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,7 +78,17 @@ class Security extends AbstractSmartyPlugin
|
||||
{
|
||||
$cart = $this->request->getSession()->getCart();
|
||||
if($cart===null || $cart->countCartItems() == 0) {
|
||||
throw new OrderException('Cart must not be empty', OrderException::CART_EMPTY);
|
||||
throw new OrderException('Cart must not be empty', OrderException::CART_EMPTY, array('empty' => 1));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public function checkValidDeliveryFunction($params, &$smarty)
|
||||
{
|
||||
$order = $this->request->getSession()->getOrder();
|
||||
if(null === $order || null === $order->chosenDeliveryAddress || null === $order->getDeliveryModuleId()) {
|
||||
throw new OrderException('Delivery must be defined', OrderException::UNDEFINED_DELIVERY, array('missing' => 1));
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -94,6 +104,7 @@ class Security extends AbstractSmartyPlugin
|
||||
return array(
|
||||
new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction'),
|
||||
new SmartyPluginDescriptor('function', 'check_cart_not_empty', $this, 'checkCartNotEmptyFunction'),
|
||||
new SmartyPluginDescriptor('function', 'check_valid_delivery', $this, 'checkValidDeliveryFunction'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,12 +25,25 @@ namespace Thelia\Exception;
|
||||
|
||||
class OrderException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* @var string The cart template name
|
||||
*/
|
||||
public $cartRoute = "cart.view";
|
||||
public $orderDeliveryRoute = "order.delivery";
|
||||
|
||||
public $arguments = array();
|
||||
|
||||
const UNKNOWN_EXCEPTION = 0;
|
||||
|
||||
const CART_EMPTY = 100;
|
||||
|
||||
public function __construct($message, $code = null, $previous = null)
|
||||
const UNDEFINED_DELIVERY = 200;
|
||||
|
||||
public function __construct($message, $code = null, $arguments = array(), $previous = null)
|
||||
{
|
||||
if(is_array($arguments)) {
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
if ($code === null) {
|
||||
$code = self::UNKNOWN_EXCEPTION;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="no-return-functions"}
|
||||
{check_auth context="front" roles="CUSTOMER" login_tpl="login"}
|
||||
{check_cart_not_empty}
|
||||
{check_valid_delivery}
|
||||
{/block}
|
||||
|
||||
{block name="breadcrumb"}
|
||||
<nav class="nav-breadcrumb" role="navigation" aria-labelledby="breadcrumb-label">
|
||||
<strong id="breadcrumb-label">You are here: </strong>
|
||||
@@ -18,10 +24,10 @@
|
||||
<h1 id="main-label" class="page-header">Your Cart</h1>
|
||||
|
||||
<div class="btn-group checkout-progress">
|
||||
<a href="cart.php" role="button" class="btn btn-step"><span class="step-nb">1</span> <span class="step-label"> <span>Your Cart</span></a>
|
||||
<a href="cart-step2.php" role="button" class="btn btn-step"><span class="step-nb">2</span> <span class="step-label">Billing and delivery</span></a>
|
||||
<a href="cart-step3.php" role="button" class="btn btn-step active"><span class="step-nb">3</span> <span class="step-label">Check my order</span></a>
|
||||
<a href="cart-step4.php" role="button" class="btn btn-step disabled"><span class="step-nb">4</span> <span class="step-label">Secure payment</span></a>
|
||||
<a href="{url path="/cart"}" role="button" class="btn btn-step"><span class="step-nb">1</span> <span class="step-label"> <span>Your Cart</span></a>
|
||||
<a href="{url path="/cart/delivery"}" role="button" class="btn btn-step"><span class="step-nb">2</span> <span class="step-label">Billing and delivery</span></a>
|
||||
<a href="#" role="button" class="btn btn-step active"><span class="step-nb">3</span> <span class="step-label">Check my order</span></a>
|
||||
<a href="#" role="button" class="btn btn-step disabled"><span class="step-nb">4</span> <span class="step-label">Secure payment</span></a>
|
||||
</div>
|
||||
|
||||
<form id="form-cart" action="cart-step4.php" method="post" role="form">
|
||||
|
||||
Reference in New Issue
Block a user