diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 8dd2eebee..f132a01da 100755 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -26,6 +26,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\ActionEvent; use Thelia\Core\Event\CustomerCreateOrUpdateEvent; +use Thelia\Core\Event\CustomerEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Customer as CustomerModel; use Thelia\Core\Event\CustomerLoginEvent; @@ -59,6 +60,13 @@ class Customer extends BaseAction implements EventSubscriberInterface } + public function delete(CustomerEvent $event) + { + $customer = $event->getCustomer(); + + $customer->delete(); + } + private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event) { $customer->setDispatcher($this->getDispatcher()); @@ -144,6 +152,7 @@ class Customer extends BaseAction implements EventSubscriberInterface TheliaEvents::CUSTOMER_UPDATEACCOUNT => array("modify", 128), TheliaEvents::CUSTOMER_LOGOUT => array("logout", 128), TheliaEvents::CUSTOMER_LOGIN => array("login" , 128), + TheliaEvents::CUSTOMER_DELETEACCOUNT => array("delete", 128), ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 60150b3fa..69d525020 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -47,6 +47,10 @@ \d+ + + Thelia\Controller\Admin\CustomerController::deleteAction + + diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index ab897d24b..322e3839d 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -25,6 +25,7 @@ namespace Thelia\Controller\Admin; use Propel\Runtime\Exception\PropelException; use Symfony\Component\Form\Form; use Thelia\Core\Event\CustomerCreateOrUpdateEvent; +use Thelia\Core\Event\CustomerEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\CustomerModification; use Thelia\Form\Exception\FormValidationException; @@ -39,22 +40,28 @@ class CustomerController extends BaseAdminController { public function indexAction() { - if (null !== $response = $this->checkAuth("admin.customers.view")) return $response; + if (null !== $response = $this->checkAuth("admin.customer.view")) return $response; return $this->render("customers", array("display_customer" => 20)); } public function viewAction($customer_id) { - if (null !== $response = $this->checkAuth("admin.customers.view")) return $response; + if (null !== $response = $this->checkAuth("admin.customer.view")) return $response; return $this->render("customer-edit", array( "customer_id" => $customer_id )); } + /** + * update customer action + * + * @param $customer_id + * @return mixed|\Symfony\Component\HttpFoundation\Response + */ public function updateAction($customer_id) { - if (null !== $response = $this->checkAuth("admin.customers.update")) return $response; + if (null !== $response = $this->checkAuth("admin.customer.update")) return $response; $message = false; @@ -108,6 +115,39 @@ class CustomerController extends BaseAdminController )); } + public function deleteAction() + { + if (null !== $response = $this->checkAuth("admin.customer.delete")) return $response; + + $message = null; + + try { + $customer_id = $this->getRequest()->get("customer_id"); + $customer = CustomerQuery::create()->findPk($customer_id); + + if(null === $customer) { + throw new \InvalidArgumentException("The customer you want to delete does not exists"); + } + + $event = new CustomerEvent($customer); + + $this->dispatch(TheliaEvents::CUSTOMER_DELETEACCOUNT, $event); + } catch(\Exception $e) { + $message = $e->getMessage(); + } + + $params = array( + "customer_page" => $this->getRequest()->get("customer_page", 1) + ); + + if ($message) { + $param["delete_error_message"] = $message; + } + + $this->redirectToRoute("admin.customers", $params); + + } + /** * @param $data * @return CustomerCreateOrUpdateEvent diff --git a/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php index 8269cecf3..d3ae6f62d 100755 --- a/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/CustomerCreateOrUpdateEvent.php @@ -1,17 +1,35 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Event; use Symfony\Component\EventDispatcher\Event; use Thelia\Model\Customer; +/** + * Class CustomerCreateOrUpdateEvent + * @package Thelia\Core\Event + * @author Manuel Raynaud + */ class CustomerCreateOrUpdateEvent extends ActionEvent { //base parameters for creating new customer diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 4cbaad675..f712dd7ae 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -71,6 +71,11 @@ final class TheliaEvents */ const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer"; + /** + * sent on customer removal + */ + const CUSTOMER_DELETEACCOUNT = "action.deleteCustomer"; + /** * sent when a customer need a new password */ @@ -103,6 +108,16 @@ final class TheliaEvents */ const AFTER_UPDATECUSTOMER = "action.after_updateCustomer"; + /** + * sent just before customer removal + */ + const BEFORE_DELETECUSTOMER = "action.before_updateCustomer"; + + /** + * sent just after customer removal + */ + const AFTER_DELETECUSTOMER = "action.after_deleteCustomer"; + // -- ADDRESS MANAGEMENT --------------------------------------------------------- /** * sent for address creation diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index bb30d18e2..f839d5f5b 100755 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -246,7 +246,7 @@ class Customer extends BaseCustomer implements UserInterface */ public function preDelete(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::BEFORE_DELETECONFIG, new CustomerEvent($this)); + $this->dispatchEvent(TheliaEvents::BEFORE_DELETECUSTOMER, new CustomerEvent($this)); return true; } @@ -255,6 +255,6 @@ class Customer extends BaseCustomer implements UserInterface */ public function postDelete(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::AFTER_DELETECONFIG, new CustomerEvent($this)); + $this->dispatchEvent(TheliaEvents::AFTER_DELETECUSTOMER, new CustomerEvent($this)); } } diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index c0fe81973..799115bf3 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -260,7 +260,8 @@ {* Delete confirmation dialog *} {capture "delete_customer_dialog"} - + + {/capture} {include @@ -271,7 +272,18 @@ dialog_message = {intl l="Do you really want to delete this customer ?"} form_action = {url path='/admin/customer/delete'} - form_content = {$smarty.capture.delete_dialog nofilter} + form_content = {$smarty.capture.delete_customer_dialog nofilter} + form_id = "form_delete_customer" } +{/block} + +{block name="javascript-initialization"} + + + {/block} \ No newline at end of file diff --git a/templates/admin/default/includes/generic-confirm-dialog.html b/templates/admin/default/includes/generic-confirm-dialog.html index b5f3ad700..be1f4b63d 100644 --- a/templates/admin/default/includes/generic-confirm-dialog.html +++ b/templates/admin/default/includes/generic-confirm-dialog.html @@ -14,6 +14,7 @@ Parameters: form_action = the form action URL, subtitted by a click on OK button form_method = the form method, default "POST" form_content = the form content + form_id = the form id *} -
+ {$form_content nofilter}