allow to delete customer address
This commit is contained in:
@@ -25,6 +25,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\Customer\CustomerAddressEvent;
|
||||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
@@ -110,6 +111,15 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
|||||||
$this->getSecurityContext()->clearCustomerUser();
|
$this->getSecurityContext()->clearCustomerUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteAddress(CustomerAddressEvent $event)
|
||||||
|
{
|
||||||
|
$address = $event->getAddress();
|
||||||
|
|
||||||
|
$address->delete();
|
||||||
|
|
||||||
|
$event->setAddress($address);
|
||||||
|
}
|
||||||
|
|
||||||
public function changePassword(ActionEvent $event)
|
public function changePassword(ActionEvent $event)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
@@ -148,11 +158,12 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
|||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
TheliaEvents::CUSTOMER_CREATEACCOUNT => array("create", 128),
|
TheliaEvents::CUSTOMER_CREATEACCOUNT => array('create', 128),
|
||||||
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),
|
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>
|
<default key="_controller">Thelia\Controller\Admin\CustomerController::deleteAction</default>
|
||||||
</route>
|
</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 -->
|
<!-- end Customer rule management -->
|
||||||
|
|
||||||
<!-- order management -->
|
<!-- order management -->
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class BaseAdminController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* Helper to append a message to the admin log.
|
* Helper to append a message to the admin log.
|
||||||
*
|
*
|
||||||
* @param unknown $message
|
* @param string $message
|
||||||
*/
|
*/
|
||||||
public function adminLogAppend($message)
|
public function adminLogAppend($message)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,13 +22,16 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Controller\Admin;
|
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\Customer\CustomerAddressEvent;
|
||||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
use Thelia\Core\Event\Customer\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;
|
||||||
|
use Thelia\Model\AddressQuery;
|
||||||
use Thelia\Model\CustomerQuery;
|
use Thelia\Model\CustomerQuery;
|
||||||
use Thelia\Core\Translation\Translator;
|
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
|
* 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";
|
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
|
* sent when a customer need a new password
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -179,7 +179,7 @@
|
|||||||
<span class="glyphicon glyphicon-pushpin"></span>
|
<span class="glyphicon glyphicon-pushpin"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a class="btn btn-default btn-xs customer-delete" title="{intl l='Delete this customer and all his orders'}" href="#delete_address_dialog" data-id="{$ID}" data-toggle="modal">
|
<a class="btn btn-default btn-xs customer-address-delete" title="{intl l='Delete this customer and all his orders'}" href="#delete_address_dialog" data-id="{$ID}" data-toggle="modal">
|
||||||
<span class="glyphicon glyphicon-trash"></span>
|
<span class="glyphicon glyphicon-trash"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -342,21 +342,21 @@
|
|||||||
|
|
||||||
{form_field form=$form field='label'}
|
{form_field form=$form field='label'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Label'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label} }" placeholder="{intl l='Label'}">
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='company'}
|
{form_field form=$form field='company'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Company'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Company'}">
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='title'}
|
{form_field form=$form field='title'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
|
|
||||||
<select name="{$name}" id="{$label_attr.for}" class="form-control">
|
<select name="{$name}" id="{$label_attr.for}" class="form-control">
|
||||||
{loop type="title" name="title1"}
|
{loop type="title" name="title1"}
|
||||||
@@ -368,54 +368,54 @@
|
|||||||
|
|
||||||
{form_field form=$form field='firstname'}
|
{form_field form=$form field='firstname'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Firstname'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Firstname'}">
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='lastname'}
|
{form_field form=$form field='lastname'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Lastname'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Lastname'}">
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='address1'}
|
{form_field form=$form field='address1'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Address'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Address'}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{form_field form=$form field='address2'}
|
{form_field form=$form field='address2'}
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Additional address'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Additional address'}">
|
||||||
{/form_field}
|
{/form_field}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{form_field form=$form field='address3'}
|
{form_field form=$form field='address3'}
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Additional address'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Additional address'}">
|
||||||
{/form_field}
|
{/form_field}
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='zipcode'}
|
{form_field form=$form field='zipcode'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Zip code'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Zip code'}">
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='city'}
|
{form_field form=$form field='city'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='City'}">
|
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='City'}">
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field='country'}
|
{form_field form=$form field='country'}
|
||||||
<div class="form-group {if $error}has-error{/if}">
|
<div class="form-group {if $error}has-error{/if}">
|
||||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
|
||||||
<select name="{$name}" id="{$label_attr.for}" class="form-control">
|
<select name="{$name}" id="{$label_attr.for}" class="form-control">
|
||||||
{loop type="country" name="country1"}
|
{loop type="country" name="country1"}
|
||||||
<option value="{$ID}">{$TITLE}</option>
|
<option value="{$ID}">{$TITLE}</option>
|
||||||
@@ -474,8 +474,8 @@
|
|||||||
dialog_title = {intl l="Delete address"}
|
dialog_title = {intl l="Delete address"}
|
||||||
dialog_message = {intl l="Do you really want to delete this address ?"}
|
dialog_message = {intl l="Do you really want to delete this address ?"}
|
||||||
|
|
||||||
form_action = {url path='/admin/address/delete'}
|
form_action = {url path='/admin/customer/address/delete'}
|
||||||
form_content = {$smarty.capture.delete_dialog nofilter}
|
form_content = {$smarty.capture.delete_address_dialog nofilter}
|
||||||
}
|
}
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
@@ -483,4 +483,14 @@
|
|||||||
{javascripts file='assets/js/main.js'}
|
{javascripts file='assets/js/main.js'}
|
||||||
<script src="{$asset_url}"></script>
|
<script src="{$asset_url}"></script>
|
||||||
{/javascripts}
|
{/javascripts}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function($) {
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("a.customer-address-delete").click(function(e){
|
||||||
|
$("#address_delete_id").val($(this).data("id"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})(jQuery);
|
||||||
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
Reference in New Issue
Block a user