From a9ecf01216f85e0ab232a735777836a30586de31 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 13 Aug 2013 10:40:04 +0200 Subject: [PATCH] complete cart controller --- .../Thelia/Config/Resources/routing/front.xml | 6 ++--- .../Controller/Front/BaseFrontController.php | 4 ++++ .../Controller/Front/CartController.php | 22 ++++++++++++++++++- core/lib/Thelia/Core/Event/TheliaEvents.php | 4 +++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 1fa147f75..116517912 100644 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -15,10 +15,10 @@ - Thelia\Controller\Front\CartController::addArticle + Thelia\Controller\Front\CartController::changeArticle - - Thelia\Controller\Front\CartController::addArticle + + Thelia\Controller\Front\CartController::deleteArticle \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index 15dfdd4bc..0ee2bd6ab 100644 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -24,7 +24,11 @@ namespace Thelia\Controller\Front; use Thelia\Controller\BaseController; +use Thelia\Tools\Redirect; class BaseFrontController extends BaseController { + public function redirect($url) { + Redirect::exec($url); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/CartController.php b/core/lib/Thelia/Controller/Front/CartController.php index 9e9e1a45a..888fc59fc 100644 --- a/core/lib/Thelia/Controller/Front/CartController.php +++ b/core/lib/Thelia/Controller/Front/CartController.php @@ -35,13 +35,26 @@ class CartController extends BaseFrontController $cartEvent = $this->getCartEvent(); $this->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent); + + $this->redirectInternal(); } public function modifyArticle() { $cartEvent = $this->getCartEvent(); - $this->dispatch(TheliaEvents::CART_CHANGEARTICLE, $cartEvent); + $this->dispatch(TheliaEvents::CART_CHANGEITEM, $cartEvent); + + $this->redirectInternal(); + } + + public function deleteArticle() + { + $cartEvent = $this->getCartEvent(); + + $this->dispatch(TheliaEvents::CART_DELETEITEM, $cartEvent); + + $this->redirectInternal(); } protected function getCartEvent() @@ -51,4 +64,11 @@ class CartController extends BaseFrontController return new CartEvent($request, $cart); } + + protected function redirectInternal() + { + if (null !== $url = $this->getRequest()->get("success_url")) { + $this->redirect($url); + } + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index f0d652323..d3a6a018d 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -136,5 +136,7 @@ final class TheliaEvents /** * sent on modify article action */ - const CART_CHANGEARTICLE = "action.changeArticle"; + const CART_CHANGEITEM = "action.changeArticle"; + + const CART_DELETEITEM = "action.deleteArticle"; } \ No newline at end of file