diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php
index b25c9c4ba..f6c6a81ad 100644
--- a/core/lib/Thelia/Action/Address.php
+++ b/core/lib/Thelia/Action/Address.php
@@ -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),
);
}
}
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index 3caa96e36..19058576e 100755
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -121,11 +121,23 @@
Thelia\Controller\Admin\CustomerController::deleteAction
-
- Thelia\Controller\Admin\CustomerController::deleteAddressAction
+
+
+
+
+
+ Thelia\Controller\Admin\AddressController::deleteAddressAction
-
+
+ Thelia\Controller\Admin\AddressController::useAddressAction
+
+
+
+ Thelia\Controller\Admin\AddressController::createAction
+
+
+
diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php
new file mode 100644
index 000000000..839b5a063
--- /dev/null
+++ b/core/lib/Thelia/Controller/Admin/AddressController.php
@@ -0,0 +1,86 @@
+. */
+/* */
+/*************************************************************************************/
+
+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
+ */
+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()));
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php
index 346a36b97..e4d24e9ad 100644
--- a/core/lib/Thelia/Controller/Admin/CustomerController.php
+++ b/core/lib/Thelia/Controller/Admin/CustomerController.php
@@ -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
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index 4d724749a..f0dc68702 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -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";
diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html
index 9c9a88486..c93f5abbc 100644
--- a/templates/admin/default/customer-edit.html
+++ b/templates/admin/default/customer-edit.html
@@ -175,7 +175,7 @@
-
+
@@ -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);