valid customer removal
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
<requirement key="customer_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="admin.customer.delete" path="/admin/customer/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\CustomerController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end Customer rule management -->
|
||||
|
||||
<!-- Order rule management -->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,17 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: manu
|
||||
* Date: 16/08/13
|
||||
* Time: 10:24
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* 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;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
/**
|
||||
* Class CustomerCreateOrUpdateEvent
|
||||
* @package Thelia\Core\Event
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CustomerCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
//base parameters for creating new customer
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,8 @@
|
||||
{* Delete confirmation 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}
|
||||
|
||||
{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"}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(".customer-delete").click(function(){
|
||||
$("#delete_customer_id").val($(this).attr("data-id"));
|
||||
});
|
||||
</script>
|
||||
|
||||
{/block}
|
||||
@@ -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
|
||||
|
||||
*}
|
||||
<div class="modal fade" id="{$dialog_id}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
@@ -28,7 +29,7 @@ Parameters:
|
||||
{$dialog_message nofilter}
|
||||
</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}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user