valid customer removal

This commit is contained in:
Manuel Raynaud
2013-09-12 12:40:14 +02:00
parent 5d87e48ba0
commit 9856528a94
8 changed files with 115 additions and 16 deletions

View File

@@ -26,6 +26,7 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\ActionEvent; use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\CustomerEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Customer as CustomerModel; use Thelia\Model\Customer as CustomerModel;
use Thelia\Core\Event\CustomerLoginEvent; 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) private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event)
{ {
$customer->setDispatcher($this->getDispatcher()); $customer->setDispatcher($this->getDispatcher());
@@ -144,6 +152,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
TheliaEvents::CUSTOMER_UPDATEACCOUNT => array("modify", 128), TheliaEvents::CUSTOMER_UPDATEACCOUNT => array("modify", 128),
TheliaEvents::CUSTOMER_LOGOUT => array("logout", 128), TheliaEvents::CUSTOMER_LOGOUT => array("logout", 128),
TheliaEvents::CUSTOMER_LOGIN => array("login" , 128), TheliaEvents::CUSTOMER_LOGIN => array("login" , 128),
TheliaEvents::CUSTOMER_DELETEACCOUNT => array("delete", 128),
); );
} }
} }

View File

@@ -47,6 +47,10 @@
<requirement key="customer_id">\d+</requirement> <requirement key="customer_id">\d+</requirement>
</route> </route>
<route id="admin.customer.delete" path="/admin/customer/delete">
<default key="_controller">Thelia\Controller\Admin\CustomerController::deleteAction</default>
</route>
<!-- end Customer rule management --> <!-- end Customer rule management -->
<!-- Order rule management --> <!-- Order rule management -->

View File

@@ -25,6 +25,7 @@ namespace Thelia\Controller\Admin;
use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Form\Form; use Symfony\Component\Form\Form;
use Thelia\Core\Event\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\CustomerEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\CustomerModification; use Thelia\Form\CustomerModification;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\Exception\FormValidationException;
@@ -39,22 +40,28 @@ class CustomerController extends BaseAdminController
{ {
public function indexAction() 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)); return $this->render("customers", array("display_customer" => 20));
} }
public function viewAction($customer_id) 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( return $this->render("customer-edit", array(
"customer_id" => $customer_id "customer_id" => $customer_id
)); ));
} }
/**
* update customer action
*
* @param $customer_id
* @return mixed|\Symfony\Component\HttpFoundation\Response
*/
public function updateAction($customer_id) 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; $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 * @param $data
* @return CustomerCreateOrUpdateEvent * @return CustomerCreateOrUpdateEvent

View File

@@ -1,17 +1,35 @@
<?php <?php
/** /*************************************************************************************/
* Created by JetBrains PhpStorm. /* */
* User: manu /* Thelia */
* Date: 16/08/13 /* */
* Time: 10:24 /* Copyright (c) OpenStudio */
* To change this template use File | Settings | File Templates. /* 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\Core\Event; namespace Thelia\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Thelia\Model\Customer; use Thelia\Model\Customer;
/**
* Class CustomerCreateOrUpdateEvent
* @package Thelia\Core\Event
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class CustomerCreateOrUpdateEvent extends ActionEvent class CustomerCreateOrUpdateEvent extends ActionEvent
{ {
//base parameters for creating new customer //base parameters for creating new customer

View File

@@ -71,6 +71,11 @@ final class TheliaEvents
*/ */
const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer"; const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer";
/**
* sent on customer removal
*/
const CUSTOMER_DELETEACCOUNT = "action.deleteCustomer";
/** /**
* sent when a customer need a new password * sent when a customer need a new password
*/ */
@@ -103,6 +108,16 @@ final class TheliaEvents
*/ */
const AFTER_UPDATECUSTOMER = "action.after_updateCustomer"; 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 --------------------------------------------------------- // -- ADDRESS MANAGEMENT ---------------------------------------------------------
/** /**
* sent for address creation * sent for address creation

View File

@@ -246,7 +246,7 @@ class Customer extends BaseCustomer implements UserInterface
*/ */
public function preDelete(ConnectionInterface $con = null) public function preDelete(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::BEFORE_DELETECONFIG, new CustomerEvent($this)); $this->dispatchEvent(TheliaEvents::BEFORE_DELETECUSTOMER, new CustomerEvent($this));
return true; return true;
} }
@@ -255,6 +255,6 @@ class Customer extends BaseCustomer implements UserInterface
*/ */
public function postDelete(ConnectionInterface $con = null) public function postDelete(ConnectionInterface $con = null)
{ {
$this->dispatchEvent(TheliaEvents::AFTER_DELETECONFIG, new CustomerEvent($this)); $this->dispatchEvent(TheliaEvents::AFTER_DELETECUSTOMER, new CustomerEvent($this));
} }
} }

View File

@@ -260,7 +260,8 @@
{* Delete confirmation dialog *} {* Delete confirmation dialog *}
{capture "delete_customer_dialog"} {capture "delete_customer_dialog"}
<input type="hidden" name="customer_id" id="customer_delete_id" value="" /> <input type="hidden" name="customer_page" value="{$customer_page}">
<input type="hidden" name="customer_id" id="delete_customer_id">
{/capture} {/capture}
{include {include
@@ -271,7 +272,18 @@
dialog_message = {intl l="Do you really want to delete this customer ?"} dialog_message = {intl l="Do you really want to delete this customer ?"}
form_action = {url path='/admin/customer/delete'} 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}
{block name="javascript-initialization"}
<script type="text/javascript">
$(".customer-delete").click(function(){
$("#delete_customer_id").val($(this).attr("data-id"));
});
</script>
{/block}

View File

@@ -14,6 +14,7 @@ Parameters:
form_action = the form action URL, subtitted by a click on OK button form_action = the form action URL, subtitted by a click on OK button
form_method = the form method, default "POST" form_method = the form method, default "POST"
form_content = the form content form_content = the form content
form_id = the form id
*} *}
<div class="modal fade" id="{$dialog_id}" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal fade" id="{$dialog_id}" tabindex="-1" role="dialog" aria-hidden="true">
@@ -28,7 +29,7 @@ Parameters:
{$dialog_message nofilter} {$dialog_message nofilter}
</div> </div>
<form method="{$form_method|default:POST}" action="{$form_action}"> <form method="{$form_method|default:POST}" action="{$form_action}" id="{$form_id}">
{$form_content nofilter} {$form_content nofilter}