put dedicated controller for address mangamenent
This commit is contained in:
@@ -60,6 +60,13 @@ class Address extends BaseAction implements EventSubscriberInterface
|
||||
$address->delete();
|
||||
}
|
||||
|
||||
public function useDefault(AddressEvent $event)
|
||||
{
|
||||
$address = $event->getAddress();
|
||||
|
||||
$address->makeItDefault();
|
||||
}
|
||||
|
||||
protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event)
|
||||
{
|
||||
$addressModel->setDispatcher($this->getDispatcher());
|
||||
@@ -125,7 +132,8 @@ class Address extends BaseAction implements EventSubscriberInterface
|
||||
return array(
|
||||
TheliaEvents::ADDRESS_CREATE => array("create", 128),
|
||||
TheliaEvents::ADDRESS_UPDATE => array("update", 128),
|
||||
TheliaEvents::ADDRESS_DELETE => array("delete", 128)
|
||||
TheliaEvents::ADDRESS_DELETE => array("delete", 128),
|
||||
TheliaEvents::ADDRESS_DEFAULT => array('useDefault', 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +121,23 @@
|
||||
<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>
|
||||
<!-- end Customer rule management -->
|
||||
|
||||
<!-- address management -->
|
||||
|
||||
<route id="admin.address.delete" path="/admin/address/delete" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\AddressController::deleteAddressAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end Customer rule management -->
|
||||
<route id="admin.address.makeItDefault" path="/admin/address/use" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\AddressController::useAddressAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.address.create" path="/admin/address/create" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\AddressController::createAction</default>
|
||||
</route>
|
||||
|
||||
<!-- end address management -->
|
||||
|
||||
<!-- order management -->
|
||||
|
||||
|
||||
86
core/lib/Thelia/Controller/Admin/AddressController.php
Normal file
86
core/lib/Thelia/Controller/Admin/AddressController.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?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\Controller\Admin;
|
||||
use Thelia\Core\Event\Address\AddressEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\AddressQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Class AddressController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressController 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 AddressEvent($address);
|
||||
|
||||
$this->dispatch(TheliaEvents::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()));
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
|
||||
public function useAddressAction()
|
||||
{
|
||||
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 AddressEvent($address);
|
||||
|
||||
$this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $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()));
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
}
|
||||
@@ -57,30 +57,7 @@ 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 AddressEvent($address);
|
||||
|
||||
$this->dispatch(TheliaEvents::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()));
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* update customer action
|
||||
|
||||
@@ -139,6 +139,11 @@ final class TheliaEvents
|
||||
*/
|
||||
const ADDRESS_DELETE = "action.deleteAddress";
|
||||
|
||||
/**
|
||||
* sent when an address is tag as default
|
||||
*/
|
||||
const ADDRESS_DEFAULT = "action.defaultAddress";
|
||||
|
||||
const BEFORE_CREATEADDRESS = "action.before_createAddress";
|
||||
const AFTER_CREATEADDRESS = "action.after_createAddress";
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
<span class="glyphicon glyphicon-edit"></span>
|
||||
</a>
|
||||
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Use this address by default'}" href="#use_address_dialog" data-toggle="modal" rel="tooltip">
|
||||
<a class="btn btn-default btn-xs customer-address-use" title="{intl l='Use this address by default'}" href="#use_address_dialog" data-id="{$ID}" data-toggle="modal" rel="tooltip">
|
||||
<span class="glyphicon glyphicon-pushpin"></span>
|
||||
</a>
|
||||
|
||||
@@ -474,7 +474,7 @@
|
||||
dialog_title = {intl l="Delete address"}
|
||||
dialog_message = {intl l="Do you really want to delete this address ?"}
|
||||
|
||||
form_action = {url path='/admin/customer/address/delete'}
|
||||
form_action = {url path='/admin/address/delete'}
|
||||
form_content = {$smarty.capture.delete_address_dialog nofilter}
|
||||
}
|
||||
{/block}
|
||||
@@ -490,6 +490,10 @@
|
||||
$("a.customer-address-delete").click(function(e){
|
||||
$("#address_delete_id").val($(this).data("id"));
|
||||
});
|
||||
|
||||
$("a.customer-address-use").click(function(e){
|
||||
$("#address_use_id").val($(this).data("id"));
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user