allow to delete customer address
This commit is contained in:
@@ -25,6 +25,7 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerAddressEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
@@ -110,6 +111,15 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$this->getSecurityContext()->clearCustomerUser();
|
||||
}
|
||||
|
||||
public function deleteAddress(CustomerAddressEvent $event)
|
||||
{
|
||||
$address = $event->getAddress();
|
||||
|
||||
$address->delete();
|
||||
|
||||
$event->setAddress($address);
|
||||
}
|
||||
|
||||
public function changePassword(ActionEvent $event)
|
||||
{
|
||||
// TODO
|
||||
@@ -148,11 +158,12 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::CUSTOMER_CREATEACCOUNT => array("create", 128),
|
||||
TheliaEvents::CUSTOMER_UPDATEACCOUNT => array("modify", 128),
|
||||
TheliaEvents::CUSTOMER_LOGOUT => array("logout", 128),
|
||||
TheliaEvents::CUSTOMER_LOGIN => array("login" , 128),
|
||||
TheliaEvents::CUSTOMER_DELETEACCOUNT => array("delete", 128),
|
||||
TheliaEvents::CUSTOMER_CREATEACCOUNT => array('create', 128),
|
||||
TheliaEvents::CUSTOMER_UPDATEACCOUNT => array('modify', 128),
|
||||
TheliaEvents::CUSTOMER_LOGOUT => array('logout', 128),
|
||||
TheliaEvents::CUSTOMER_LOGIN => array('login', 128),
|
||||
TheliaEvents::CUSTOMER_DELETEACCOUNT => array('delete', 128),
|
||||
TheliaEvents::CUSTOMER_ADDRESS_DELETE => array('deleteAddress', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,10 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\CustomerController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.customer.address.delete" path="/admin/customer/address/delete" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\CustomerController::deleteAddressAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end Customer rule management -->
|
||||
|
||||
<!-- order management -->
|
||||
|
||||
@@ -51,7 +51,7 @@ class BaseAdminController extends BaseController
|
||||
/**
|
||||
* Helper to append a message to the admin log.
|
||||
*
|
||||
* @param unknown $message
|
||||
* @param string $message
|
||||
*/
|
||||
public function adminLogAppend($message)
|
||||
{
|
||||
|
||||
@@ -22,13 +22,16 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Thelia\Core\Event\Customer\CustomerAddressEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\CustomerModification;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
@@ -53,6 +56,33 @@ class CustomerController extends BaseAdminController
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteAddressAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customer.update")) return $response;
|
||||
|
||||
$address_id = $this->getRequest()->request->get('address_id');
|
||||
|
||||
try {
|
||||
$address = AddressQuery::create()->findPk($address_id);
|
||||
|
||||
if (null === $address) {
|
||||
throw new \InvalidArgumentException(sprintf('%d address does not exists', $address_id));
|
||||
}
|
||||
|
||||
$addressEvent = new CustomerAddressEvent($address);
|
||||
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_ADDRESS_DELETE, $addressEvent);
|
||||
|
||||
$this->adminLogAppend(sprintf("address %d for customer %d removal", $address_id, $address->getCustomerId()));
|
||||
} catch(\Exception $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during address removal with message %s", $e->getMessage()));
|
||||
}
|
||||
|
||||
return $this->render("customer-edit", array(
|
||||
"customer_id" => $address->getCustomerId()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* update customer action
|
||||
*
|
||||
|
||||
66
core/lib/Thelia/Core/Event/Customer/CustomerAddressEvent.php
Normal file
66
core/lib/Thelia/Core/Event/Customer/CustomerAddressEvent.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* 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\Customer;
|
||||
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Model\Address;
|
||||
|
||||
|
||||
/**
|
||||
* Class CustomerAddressEvent
|
||||
* @package Thelia\Core\Event\Customer
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CustomerAddressEvent extends ActionEvent
|
||||
{
|
||||
/**
|
||||
* @var \Thelia\Model\Address
|
||||
*/
|
||||
protected $address;
|
||||
|
||||
/**
|
||||
* @param Address $address
|
||||
*/
|
||||
public function __construct(Address $address)
|
||||
{
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Thelia\Model\Address $address
|
||||
*/
|
||||
public function setAddress($address)
|
||||
{
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Address
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,6 +76,11 @@ final class TheliaEvents
|
||||
*/
|
||||
const CUSTOMER_DELETEACCOUNT = "action.deleteCustomer";
|
||||
|
||||
/**
|
||||
* sent on customer address removal
|
||||
*/
|
||||
const CUSTOMER_ADDRESS_DELETE = "action.customer.deleteAddress";
|
||||
|
||||
/**
|
||||
* sent when a customer need a new password
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user