From fa45df32757c156f5eafb8407e93a062fb0d656c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 3 Oct 2013 15:53:30 +0200 Subject: [PATCH 1/9] allow to delete customer address --- core/lib/Thelia/Action/Customer.php | 21 ++++-- .../Thelia/Config/Resources/routing/admin.xml | 4 ++ .../Controller/Admin/BaseAdminController.php | 2 +- .../Controller/Admin/CustomerController.php | 30 +++++++++ .../Event/Customer/CustomerAddressEvent.php | 66 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 5 ++ templates/admin/default/customer-edit.html | 52 +++++++++------ 7 files changed, 153 insertions(+), 27 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/Customer/CustomerAddressEvent.php diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 061dba028..46a7396c1 100755 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -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) ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 509162cbf..3caa96e36 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -121,6 +121,10 @@ Thelia\Controller\Admin\CustomerController::deleteAction + + Thelia\Controller\Admin\CustomerController::deleteAddressAction + + diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 2401617f3..61fc80940 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -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) { diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index f559a5bb0..0c320f0d4 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -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 * diff --git a/core/lib/Thelia/Core/Event/Customer/CustomerAddressEvent.php b/core/lib/Thelia/Core/Event/Customer/CustomerAddressEvent.php new file mode 100644 index 000000000..6c4c82d3d --- /dev/null +++ b/core/lib/Thelia/Core/Event/Customer/CustomerAddressEvent.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Customer; + +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Address; + + +/** + * Class CustomerAddressEvent + * @package Thelia\Core\Event\Customer + * @author Manuel Raynaud + */ +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; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 9ffe08bcb..4d724749a 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -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 */ diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index 9bcba75b9..9c9a88486 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -179,7 +179,7 @@ - + @@ -342,21 +342,21 @@ {form_field form=$form field='label'}
- - + +
{/form_field} {form_field form=$form field='company'}
- - + +
{/form_field} {form_field form=$form field='title'}
- + + +
{/form_field} {form_field form=$form field='lastname'}
- - + +
{/form_field} {form_field form=$form field='address1'}
- - + +
{form_field form=$form field='address2'} - + {/form_field}
{form_field form=$form field='address3'} - + {/form_field}
{/form_field} {form_field form=$form field='zipcode'}
- - + +
{/form_field} {form_field form=$form field='city'}
- - + +
{/form_field} {form_field form=$form field='country'}
- + +
+ {/form_field} + + {form_field form=$form field='company'} +
+ + +
+ {/form_field} + + {form_field form=$form field='title'} +
+ + + +
+ {/form_field} + + {form_field form=$form field='firstname'} +
+ + +
+ {/form_field} + + {form_field form=$form field='lastname'} +
+ + +
+ {/form_field} + + {form_field form=$form field='address1'} +
+ + +
+ +
+ {form_field form=$form field='address2'} + + {/form_field} +
+ +
+ {form_field form=$form field='address3'} + + {/form_field} +
+ {/form_field} + + {form_field form=$form field='zipcode'} +
+ + +
+ {/form_field} + + {form_field form=$form field='city'} +
+ + +
+ {/form_field} + + {form_field form=$form field='country'} +
+ + +
+ {/form_field} + +{/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "edit_address_dialog" + dialog_title = {intl l="Edit an address"} + dialog_body = {$smarty.capture.edit_address_dialog nofilter} + +dialog_ok_label = {intl l="Edit this address"} +dialog_cancel_label = {intl l="Cancel"} + +form_action = {url path='/admin/address/update'} +form_enctype = {form_enctype form=$form} +form_error_message = $form_error_message +} + +{/form} \ No newline at end of file diff --git a/templates/admin/default/assets/less/thelia/thelia.less b/templates/admin/default/assets/less/thelia/thelia.less index fc2652004..c844b6163 100644 --- a/templates/admin/default/assets/less/thelia/thelia.less +++ b/templates/admin/default/assets/less/thelia/thelia.less @@ -295,6 +295,15 @@ width: auto; } +.loading-global{ + background: url("@{imgDir}/ajax-loader.gif") no-repeat; + height: 30px; + display: inline-block; + line-height: 30px; + padding-left: 40px; + width: auto; +} + .existing-image .col-sm-6{ position: relative; diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index c93f5abbc..c8ae95218 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -171,7 +171,7 @@
- + @@ -218,7 +218,7 @@
- +
{* Add an Address *} {form name="thelia.address.create"} @@ -227,7 +227,10 @@ {capture "address_creation_dialog"} {form_hidden_fields form=$form} - + + {form_field form=$form field='success_url'} + + {/form_field} {form_field form=$form field='label'}
@@ -246,7 +249,7 @@
- {loop type="title" name="title1"} {/loop} @@ -257,21 +260,21 @@ {form_field form=$form field='firstname'}
- +
{/form_field} {form_field form=$form field='lastname'}
- +
{/form_field} {form_field form=$form field='address1'}
- +
@@ -290,21 +293,21 @@ {form_field form=$form field='zipcode'}
- +
{/form_field} {form_field form=$form field='city'}
- +
{/form_field} {form_field form=$form field='country'}
- {loop type="country" name="country1"} {/loop} @@ -331,117 +334,7 @@ {/form} - {* Update an Address *} - {form name="thelia.address.update"} - - {* Capture the dialog body, to pass it to the generic dialog *} - {capture "edit_address_dialog"} - - {form_hidden_fields form=$form} - - {form_field form=$form field='label'} -
- - -
- {/form_field} - - {form_field form=$form field='company'} -
- - -
- {/form_field} - - {form_field form=$form field='title'} -
- - - -
- {/form_field} - - {form_field form=$form field='firstname'} -
- - -
- {/form_field} - - {form_field form=$form field='lastname'} -
- - -
- {/form_field} - - {form_field form=$form field='address1'} -
- - -
- -
- {form_field form=$form field='address2'} - - {/form_field} -
- -
- {form_field form=$form field='address3'} - - {/form_field} -
- {/form_field} - - {form_field form=$form field='zipcode'} -
- - -
- {/form_field} - - {form_field form=$form field='city'} -
- - -
- {/form_field} - - {form_field form=$form field='country'} -
- - -
- {/form_field} - - {/capture} - - {include - file = "includes/generic-create-dialog.html" - - dialog_id = "edit_address_dialog" - dialog_title = {intl l="Edit an address"} - dialog_body = {$smarty.capture.edit_address_dialog nofilter} - - dialog_ok_label = {intl l="Edit this address"} - dialog_cancel_label = {intl l="Cancel"} - - form_action = {url path='/admin/address/update'} - form_enctype = {form_enctype form=$form} - form_error_message = $form_error_message - } - - {/form} {* Default confirmation dialog *} @@ -494,6 +387,20 @@ $("a.customer-address-use").click(function(e){ $("#address_use_id").val($(this).data("id")); }); + + $("a.customer-update-address").click(function(e){ + var baseUrl = "{url path="/admin/address/update/"}"; + //$('body').html('
'); + $.ajax({ + method: 'get', + url: baseUrl+$(this).data('id') + }).done(function(data){ + //$(".loading").remove(); + $("#address-update-modal").html(data); + $("#edit_address_dialog").modal("show"); + }); + + }); }); })(jQuery); From e2ccf3714b6c73173d7b9297ecbdc7ae06f240d5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 4 Oct 2013 12:22:22 +0200 Subject: [PATCH 5/9] display customer edit form --- .../admin/default/ajax/address-update-modal.html | 4 ++-- .../admin/default/assets/less/thelia/thelia.less | 12 +++++------- templates/admin/default/customer-edit.html | 7 +++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/templates/admin/default/ajax/address-update-modal.html b/templates/admin/default/ajax/address-update-modal.html index 9dce39aa8..d6a329118 100644 --- a/templates/admin/default/ajax/address-update-modal.html +++ b/templates/admin/default/ajax/address-update-modal.html @@ -27,7 +27,7 @@
@@ -85,7 +85,7 @@
diff --git a/templates/admin/default/assets/less/thelia/thelia.less b/templates/admin/default/assets/less/thelia/thelia.less index c844b6163..11dc5bd74 100644 --- a/templates/admin/default/assets/less/thelia/thelia.less +++ b/templates/admin/default/assets/less/thelia/thelia.less @@ -295,13 +295,11 @@ width: auto; } -.loading-global{ - background: url("@{imgDir}/ajax-loader.gif") no-repeat; - height: 30px; - display: inline-block; - line-height: 30px; - padding-left: 40px; - width: auto; +.modal-backdrop .loading { + left: 50%; + top: 50%; + right: auto; + position: absolute; } diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index c8ae95218..b8c4138b3 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -390,16 +390,19 @@ $("a.customer-update-address").click(function(e){ var baseUrl = "{url path="/admin/address/update/"}"; - //$('body').html('
'); + $('body').append(''); $.ajax({ method: 'get', url: baseUrl+$(this).data('id') }).done(function(data){ - //$(".loading").remove(); + $("#loading-event").remove(); $("#address-update-modal").html(data); $("#edit_address_dialog").modal("show"); }); + }); + $(document).on("hidden.bs.modal", "#edit_address_dialog", function(ev){ + $("#edit_address_dialog").remove(); }); }); })(jQuery); From 52ab1c1b7256b5dfed8fc1d527d4bd04b8ff0c27 Mon Sep 17 00:00:00 2001 From: gmorel Date: Fri, 4 Oct 2013 16:52:29 +0200 Subject: [PATCH 6/9] Working : Allow fixtures in module, refactor explode on sql file : add \n otherwise any ; in the db crashes everything --- core/lib/Thelia/Install/Database.php | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Install/Database.php b/core/lib/Thelia/Install/Database.php index 648a6431a..d17bd7c3d 100644 --- a/core/lib/Thelia/Install/Database.php +++ b/core/lib/Thelia/Install/Database.php @@ -40,21 +40,33 @@ class Database /** * Insert all sql needed in database + * Default insert /install/thelia.sql and /install/insert.sql * - * @param $dbName + * @param string $dbName Database name + * @param array $extraSqlFiles SQL Files uri to insert */ - public function insertSql($dbName = null) + public function insertSql($dbName = null, array $extraSqlFiles = null) { - if($dbName) { + if ($dbName) { $this->connection->query(sprintf("use %s", $dbName)); } $sql = array(); - $sql = array_merge( - $sql, - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) - ); + + if (null === $extraSqlFiles) { + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents(THELIA_ROOT . '/install/thelia.sql')), + $this->prepareSql(file_get_contents(THELIA_ROOT . '/install/insert.sql')) + ); + } else { + foreach ($extraSqlFiles as $fileToInsert) { + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents($fileToInsert)) + ); + } + } for ($i = 0; $i < count($sql); $i ++) { if (!empty($sql[$i])) { @@ -75,7 +87,7 @@ class Database $sql = trim($sql); $query = array(); - $tab = explode(";", $sql); + $tab = explode(";\n", $sql); for ($i=0; $i Date: Fri, 4 Oct 2013 17:33:48 +0200 Subject: [PATCH 7/9] update address process --- .../Thelia/Config/Resources/routing/admin.xml | 5 ++ .../Controller/Admin/AddressController.php | 50 +++++++------------ .../default/ajax/address-update-modal.html | 2 +- templates/default/layout.tpl | 18 ------- templates/default/product.html | 2 +- 5 files changed, 25 insertions(+), 52 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index c856c1a90..2f85b57bc 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -142,6 +142,11 @@ \d+ + + Thelia\Controller\Admin\AddressController::processUpdateAction + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php index 6f4622598..c6af8102c 100644 --- a/core/lib/Thelia/Controller/Admin/AddressController.php +++ b/core/lib/Thelia/Controller/Admin/AddressController.php @@ -60,31 +60,6 @@ class AddressController extends AbstractCrudController ); } -/* 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; @@ -159,7 +134,13 @@ class AddressController extends AbstractCrudController */ protected function getCreationEvent($formData) { - return $this->getCreateOrUpdateEvent($formData); + $event = $this->getCreateOrUpdateEvent($formData); + + $customer = CustomerQuery::create()->findPk($this->getRequest()->get("customer_id")); + + $event->setCustomer($customer); + + return $event; } /** @@ -169,7 +150,9 @@ class AddressController extends AbstractCrudController */ protected function getUpdateEvent($formData) { - return $this->getCreateOrUpdateEvent($formData); + $event = $this->getCreateOrUpdateEvent($formData); + + $event->setAddress($this->getExistingObject()); } protected function getCreateOrUpdateEvent($formData) @@ -191,9 +174,7 @@ class AddressController extends AbstractCrudController $formData["is_default"] ); - $customer = CustomerQuery::create()->findPk($this->getRequest()->get("customer_id")); - $event->setCustomer($customer); return $event; @@ -281,7 +262,8 @@ class AddressController extends AbstractCrudController */ protected function redirectToEditionTemplate() { - // TODO: Implement redirectToEditionTemplate() method. + $address = $this->getExistingObject(); + $this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId())); } /** @@ -312,7 +294,11 @@ class AddressController extends AbstractCrudController */ protected function performAdditionalCreateAction($createEvent) { - $address = $createEvent->getAddress(); - $this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId())); + $this->redirectToEditionTemplate(); + } + + protected function performAdditionalUpdateAction($event) + { + $this->redirectToEditionTemplate(); } } \ No newline at end of file diff --git a/templates/admin/default/ajax/address-update-modal.html b/templates/admin/default/ajax/address-update-modal.html index d6a329118..39bafccea 100644 --- a/templates/admin/default/ajax/address-update-modal.html +++ b/templates/admin/default/ajax/address-update-modal.html @@ -103,7 +103,7 @@ dialog_ok_label = {intl l="Edit this address"} dialog_cancel_label = {intl l="Cancel"} -form_action = {url path='/admin/address/update'} +form_action = {url path="/admin/address/save/{$address_id}"} form_enctype = {form_enctype form=$form} form_error_message = $form_error_message } diff --git a/templates/default/layout.tpl b/templates/default/layout.tpl index 731c6f685..2c8a56d44 100644 --- a/templates/default/layout.tpl +++ b/templates/default/layout.tpl @@ -62,24 +62,6 @@ URL: http://www.thelia.net