From bad8a0439d72b7c15bfa2cbf9280736442a55ae7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 12 Sep 2013 17:28:02 +0200 Subject: [PATCH 01/10] fix test suite --- .../Exception/NotFountHttpException.php | 46 +++++++++++++++++++ core/lib/Thelia/Model/Address.php | 14 ++---- core/lib/Thelia/Tests/Action/CustomerTest.php | 2 + 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 core/lib/Thelia/Core/HttpKernel/Exception/NotFountHttpException.php diff --git a/core/lib/Thelia/Core/HttpKernel/Exception/NotFountHttpException.php b/core/lib/Thelia/Core/HttpKernel/Exception/NotFountHttpException.php new file mode 100644 index 000000000..a52f0eb86 --- /dev/null +++ b/core/lib/Thelia/Core/HttpKernel/Exception/NotFountHttpException.php @@ -0,0 +1,46 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Core\HttpKernel\Exceptions; + +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException as BaseNotFountHttpException; +/** + * Class NotFountHttpException + * @author Manuel Raynaud + */ +class NotFountHttpException extends BaseNotFountHttpException { + + protected $adminContext = false; + + public function __construct($message = null, \Exception $previous = null, $code = 0, $adminContext = false) + { + $this->adminContext = $adminContext; + + parent::__construct($message, $previous, $code); + } + + public function isAdminContext() + { + return $this->adminContext === true; + + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index 5ce697e8f..dbd334ba2 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -58,6 +58,10 @@ class Address extends BaseAddress { */ public function preDelete(ConnectionInterface $con = null) { + if($this->getIsDefault()) { + return false; + } + $this->dispatchEvent(TheliaEvents::BEFORE_DELETEADDRESS, new AddressEvent($this)); return true; } @@ -71,14 +75,4 @@ class Address extends BaseAddress { $this->dispatchEvent(TheliaEvents::AFTER_DELETEADDRESS, new AddressEvent($this)); } - public function preSave() - { - $valid = true; - if($this->getIsDefault()) { - $valid = false; - } - - return $valid; - } - } diff --git a/core/lib/Thelia/Tests/Action/CustomerTest.php b/core/lib/Thelia/Tests/Action/CustomerTest.php index b70d39428..10ba01587 100644 --- a/core/lib/Thelia/Tests/Action/CustomerTest.php +++ b/core/lib/Thelia/Tests/Action/CustomerTest.php @@ -86,6 +86,8 @@ class CustomerTest extends \PHPUnit_Framework_TestCase $addressCreated = $customerCreated->getDefaultAddress(); + $this->assertInstanceOf("Thelia\Model\Address", $addressCreated); + $this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname()); $this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname()); $this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId()); From d1d9892ae8b851c42c1588c396c53765bd91e68c Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 12 Sep 2013 22:10:51 +0200 Subject: [PATCH 02/10] absoluteUrl prevetn duplicate parameters in generated URL --- core/lib/Thelia/Tools/URL.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 05084c0c1..650cb9de1 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -140,8 +140,14 @@ class URL if (! is_null($parameters)) { foreach ($parameters as $name => $value) { + + // Remove this parameter from base URL to prevent duplicate parameters + $base = preg_replace('/([?&])'.$name.'=([^&])*(&|$)/', '$1', $base); + $queryString .= sprintf("%s=%s&", urlencode($name), urlencode($value)); } + + $base = rtrim($base, '&'); } $sepChar = strstr($base, '?') === false ? '?' : '&'; From 6a66a3f99ac0a10e5bdf6db8b752c0c02bdaa9fa Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 00:16:29 +0200 Subject: [PATCH 03/10] Fixed duplication parameter check regexp --- core/lib/Thelia/Tools/URL.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 650cb9de1..5dc6c20c9 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -146,8 +146,6 @@ class URL $queryString .= sprintf("%s=%s&", urlencode($name), urlencode($value)); } - - $base = rtrim($base, '&'); } $sepChar = strstr($base, '?') === false ? '?' : '&'; From 316043d93a9e9231a31280112560814bb7a9f527 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 00:18:19 +0200 Subject: [PATCH 04/10] Fixed action column alignment --- .../default/assets/less/thelia/tables.less | 7 +++ templates/admin/default/attribute-edit.html | 22 ++++--- templates/admin/default/attributes.html | 62 ++++++++++++++++++- templates/admin/default/categories.html | 2 +- templates/admin/default/currencies.html | 2 +- templates/admin/default/customers.html | 24 +++---- .../default/includes/inner-form-toolbar.html | 2 +- .../standard-description-form-fields.html | 8 +-- .../default/includes/thelia_news_feed.html | 3 +- templates/admin/default/orders.html | 14 ++--- 10 files changed, 111 insertions(+), 35 deletions(-) diff --git a/templates/admin/default/assets/less/thelia/tables.less b/templates/admin/default/assets/less/thelia/tables.less index d8b3a9e4e..5997840a8 100755 --- a/templates/admin/default/assets/less/thelia/tables.less +++ b/templates/admin/default/assets/less/thelia/tables.less @@ -55,6 +55,13 @@ .table-left-aligned { th, td { text-align: left; + + &.text-center { + text-align: center; + } + &.text-right { + text-align: right; + } } select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input { diff --git a/templates/admin/default/attribute-edit.html b/templates/admin/default/attribute-edit.html index 1b290f222..882edd60c 100644 --- a/templates/admin/default/attribute-edit.html +++ b/templates/admin/default/attribute-edit.html @@ -37,6 +37,10 @@

{intl l='Attribute information'}

+ {form_field form=$form field='id'} + + {/form_field} + {* Be sure to get the attribute ID, even if the form could not be validated *} @@ -52,7 +56,7 @@ {if $form_error}
{$form_error_message}
{/if} - {include file="includes/standard-description-form-fields.html"} + {include file="includes/standard-description-form-fields.html" form=$form}
@@ -79,9 +83,10 @@ {admin_sortable_header - current_order=$order + current_order=$attributeav_order order='id' reverse_order='id_reverse' + request_parameter_name='attributeav_order' path={url path='/admin/configuration/attributes/update' attribute_id=$attribute_id} label="{intl l='ID'}" } @@ -89,9 +94,10 @@ {admin_sortable_header - current_order=$order + current_order=$attributeav_order order='alpha' reverse_order='alpha_reverse' + request_parameter_name='attributeav_order' path={url path='/admin/configuration/attributes/update' attribute_id=$attribute_id} label="{intl l='Value'}" } @@ -99,9 +105,10 @@ {admin_sortable_header - current_order=$order + current_order=$attributeav_order order='manual' reverse_order='manual_reverse' + request_parameter_name='attributeav_order' path={url path='/admin/configuration/attributes/update' attribute_id=$attribute_id} label="{intl l="Position"}" } @@ -114,12 +121,13 @@ - {loop name="list" type="attribute_availability" attribute=$attribute_id backend_context="1" lang=$edit_language_id order=$order} + {loop name="list" type="attribute_availability" attribute=$attribute_id backend_context="1" lang=$edit_language_id order=$attributeav_order} {$ID} - + {* FIXME : integrate this in the encolsing form to provide standard form processing *} + @@ -151,7 +159,7 @@
- {intl l="No product attribute has been created yet. Click the + button to create one."} + {intl l="No value has been created yet. Click the + button to create one."}
diff --git a/templates/admin/default/attributes.html b/templates/admin/default/attributes.html index eab4996ac..57fd9c256 100644 --- a/templates/admin/default/attributes.html +++ b/templates/admin/default/attributes.html @@ -97,6 +97,17 @@ {module_include location='attributes_table_row'} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.attributes.change"} + + {/loop} +
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.attributes.change"} @@ -213,10 +224,51 @@ dialog_title = {intl l="Delete attribute"} dialog_message = {intl l="Do you really want to delete this attribute ? It will be removed from all product templates."} - form_action = {url path='/admin/configuration/attributes/delete'} + form_action = {url path='/admin/configuration/attributes/remove_from-all-templates' attribute_id=$ID} form_content = {$smarty.capture.delete_dialog nofilter} } + +{* Add to all dialog *} + +{capture "add_to_all_dialog"} + + + {module_include location='attribute_add_to_all_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "add_to_all_dialog" + dialog_title = {intl l="Add to all product templates"} + dialog_message = {intl l="Do you really want to add this attribute to all product templates ?"} + + form_action = {url path='/admin/configuration/attributes/add-to-all-templates'} + form_content = {$smarty.capture.add_to_all_dialog nofilter} +} + +{* Remove from all dialog *} + +{capture "remove_from_all_dialog"} + + + {module_include location='attribute_add_to_all_form'} + +{/capture} + +{include + file = "includes/generic-confirm-dialog.html" + + dialog_id = "remove_from_all_dialog" + dialog_title = {intl l="Remove from all product templates"} + dialog_message = {intl l="Do you really want to remove this attribute from all product templates ? You'll loose all product related data for this attribute."} + + form_action = {url path='/admin/configuration/attributes/remove-from-all-templates'} + form_content = {$smarty.capture.remove_from_all_dialog nofilter} +} + {/block} {block name="javascript-initialization"} @@ -233,6 +285,14 @@ $('#attribute_delete_id').val($(this).data('id')); }); + $('a.attribute-add-to-all').click(function(ev) { + $('#attribute_add_to_all_id').val($(this).data('id')); + }); + + $('a.attribute-remove-from-all').click(function(ev) { + $('#attribute_remove_from_all_id').val($(this).data('id')); + }); + // JS stuff for creation form {include file = "includes/generic-js-dialog.html" diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 0423bcc66..6fe06f8bc 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -82,7 +82,7 @@ } - {intl l='Actions'} + {intl l='Actions'} diff --git a/templates/admin/default/currencies.html b/templates/admin/default/currencies.html index 72bf01e75..fe4cfe882 100644 --- a/templates/admin/default/currencies.html +++ b/templates/admin/default/currencies.html @@ -111,7 +111,7 @@ {module_include location='currencies_table_header'} - {intl l='Actions'} + {intl l='Actions'} diff --git a/templates/admin/default/customers.html b/templates/admin/default/customers.html index 799115bf3..72179f667 100644 --- a/templates/admin/default/customers.html +++ b/templates/admin/default/customers.html @@ -11,9 +11,9 @@
- + @@ -58,7 +58,7 @@ {intl l='order amount'} - {intl l='Actions'} + {intl l='Actions'} @@ -154,23 +154,23 @@ {* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *} {/form_field} - + {form_field form=$form field='company'}
{/form_field} - - {form_field form=$form field='title'} + + {form_field form=$form field='title'}
- + +
{/form_field} @@ -191,13 +191,13 @@ {form_field form=$form field='address1'}
- +
{form_field form=$form field='address2'} - {/form_field} + {/form_field}
@@ -237,8 +237,8 @@
- {/form_field} - + {/form_field} + {/capture} {include diff --git a/templates/admin/default/includes/inner-form-toolbar.html b/templates/admin/default/includes/inner-form-toolbar.html index 518c204e3..c142cbdd7 100755 --- a/templates/admin/default/includes/inner-form-toolbar.html +++ b/templates/admin/default/includes/inner-form-toolbar.html @@ -12,7 +12,7 @@
{/form_field} @@ -25,7 +25,7 @@ {intl l="The détailed description."} - +
{/form_field} @@ -36,6 +36,6 @@ {intl l="A short post-description information"} - +
{/form_field} \ No newline at end of file diff --git a/templates/admin/default/includes/thelia_news_feed.html b/templates/admin/default/includes/thelia_news_feed.html index 6b9d2b5a9..09b3af020 100755 --- a/templates/admin/default/includes/thelia_news_feed.html +++ b/templates/admin/default/includes/thelia_news_feed.html @@ -4,7 +4,8 @@

{$DATE}

{$TITLE|strip_tags nofilter}

-

{$DESCRIPTION|strip_tags|truncate:250:"...":true nofilter}

+ {* we use unescape:"htmlall" to unescape var before truncate, to prevent a cut in the middel of an HTML entity, eg &ea... *} +

{$DESCRIPTION|strip_tags|unescape:"htmlall"|truncate:250:"...":true nofilter}

{intl l='Lire la suite »'}

{/loop} diff --git a/templates/admin/default/orders.html b/templates/admin/default/orders.html index 947c615a3..4f9c6ecf8 100644 --- a/templates/admin/default/orders.html +++ b/templates/admin/default/orders.html @@ -17,7 +17,7 @@ {module_include location='orders_top'}
-
+
- + {module_include location='orders_table_header'} - + - + @@ -116,7 +116,7 @@ - + - +
@@ -36,14 +36,14 @@
{intl l="Name"} {intl l="Amount"} {intl l="Status"}{intl l="Actions"}{intl l="Actions"}
01230450123045
-
+
From ca7d1f7c85de546fb754ac97b95070d4bd26d613 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 13 Sep 2013 00:19:53 +0200 Subject: [PATCH 05/10] Finished attributes management --- core/lib/Thelia/Action/Attribute.php | 24 +++ .../Thelia/Config/Resources/routing/admin.xml | 8 + .../Admin/AbstractCrudController.php | 74 +++++--- .../Admin/AttributeAvController.php | 60 +++--- .../Controller/Admin/AttributeController.php | 171 +++++++++++++++--- .../Controller/Admin/BaseAdminController.php | 33 +++- .../Controller/Admin/ConfigController.php | 1 + .../Controller/Admin/CurrencyController.php | 1 + .../Controller/Admin/MessageController.php | 52 ++++-- core/lib/Thelia/Core/Event/TheliaEvents.php | 3 + .../Template/Loop/AttributeAvailability.php | 8 +- .../Smarty/Plugins/AdminUtilities.php | 5 +- .../Core/Template/Smarty/Plugins/Form.php | 80 +++++--- .../Template/Smarty/Plugins/UrlGenerator.php | 1 + .../Thelia/Form/AttributeModificationForm.php | 2 + 15 files changed, 406 insertions(+), 117 deletions(-) diff --git a/core/lib/Thelia/Action/Attribute.php b/core/lib/Thelia/Action/Attribute.php index 8524f6054..2877ca388 100644 --- a/core/lib/Thelia/Action/Attribute.php +++ b/core/lib/Thelia/Action/Attribute.php @@ -37,6 +37,8 @@ use Thelia\Model\ConfigQuery; use Thelia\Model\AttributeAv; use Thelia\Model\AttributeAvQuery; use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Event\CategoryEvent; +use Thelia\Core\Event\AttributeEvent; class Attribute extends BaseAction implements EventSubscriberInterface { @@ -133,6 +135,24 @@ class Attribute extends BaseAction implements EventSubscriberInterface } } + public function addToAllTemplates(AttributeEvent $event) + { + $templates = ProductTemplateAttributeQuery::create()->find(); + + foreach($templates as $template) { + $pat = new ProductTemplateAttribute(); + + $pat->setTemplate($template->getId()) + ->setAttributeId($event->getAttribute()->getId()) + ->save(); + } + } + + public function removeFromAllTemplates(AttributeEvent $event) + { + // Delete this attribute from all product templates + ProductTemplateAttributeQuery::create()->filterByAttributeId($event->getAttribute()->getId())->delete(); + } /** * {@inheritDoc} @@ -144,6 +164,10 @@ class Attribute extends BaseAction implements EventSubscriberInterface TheliaEvents::ATTRIBUTE_UPDATE => array("update", 128), TheliaEvents::ATTRIBUTE_DELETE => array("delete", 128), TheliaEvents::ATTRIBUTE_UPDATE_POSITION => array("updatePosition", 128), + + TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES => array("removeFromAllTemplates", 128), + TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES => array("addToAllTemplates", 128), + ); } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index c76e70eda..c16ee05bd 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -236,6 +236,14 @@ Thelia\Controller\Admin\AttributeController::updatePositionAction + + Thelia\Controller\Admin\AttributeController::removeFromAllTemplates + + + + Thelia\Controller\Admin\AttributeController::addToAllTemplates + + Thelia\Controller\Admin\AttributeAvController::createAction diff --git a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php index 1dcbca01f..31f9ba72a 100644 --- a/core/lib/Thelia/Controller/Admin/AbstractCrudController.php +++ b/core/lib/Thelia/Controller/Admin/AbstractCrudController.php @@ -38,6 +38,7 @@ abstract class AbstractCrudController extends BaseAdminController // List ordering protected $defaultListOrder; + protected $orderRequestParameterName; // Permissions protected $viewPermissionIdentifier; @@ -74,6 +75,7 @@ abstract class AbstractCrudController extends BaseAdminController $objectName, $defaultListOrder = null, + $orderRequestParameterName = null, $viewPermissionIdentifier, $createPermissionIdentifier, @@ -89,8 +91,9 @@ abstract class AbstractCrudController extends BaseAdminController $this->objectName = $objectName; $this->defaultListOrder = $defaultListOrder; + $this->orderRequestParameterName = $orderRequestParameterName; - $this->viewPermissionIdentifier = $viewPermissionIdentifier; + $this->viewPermissionIdentifier = $viewPermissionIdentifier; $this->createPermissionIdentifier = $createPermissionIdentifier; $this->updatePermissionIdentifier = $updatePermissionIdentifier; $this->deletePermissionIdentifier = $deletePermissionIdentifier; @@ -194,36 +197,56 @@ abstract class AbstractCrudController extends BaseAdminController protected abstract function redirectToListTemplate(); - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { throw new \LogicException ("Position Update is not supported for this object"); } - protected function createToggleVisibilityEvent() { - + protected function createToggleVisibilityEvent() + { throw new \LogicException ("Toggle Visibility is not supported for this object"); } + /** + * Put in this method post object creation processing if required. + * + * @param unknown $createdObject the created object + */ + protected function performAdditionalCreateAction($createdObject) + { + // Nothing to do + } + + /** + * Put in this method post object update processing if required. + * + * @param unknown $updatedObject the updated object + */ + protected function performAdditionalUpdateAction($updatedObject) + { + // Nothing to do + } + + /** + * Put in this method post object delete processing if required. + * + * @param unknown $deletedObject the deleted object + */ + protected function performAdditionalDeleteAction($deletedObject) + { + // Nothing to do + } + /** * Return the current list order identifier, updating it in the same time. */ - protected function getCurrentListOrder($update_session = true) { - - $order = null; - - if ($this->defaultListOrder) { - - $orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $this->objectName); - - // Find the current order - $order = $this->getRequest()->get( - 'order', - $this->getSession()->get($orderSessionIdentifier, $this->defaultListOrder) - ); - - if ($update_session) $this->getSession()->set($orderSessionIdentifier, $order); - } - - return $order; + protected function getCurrentListOrder($update_session = true) + { + return $this->getListOrderFromSession( + $this->objectName, + $this->orderRequestParameterName, + $this->defaultListOrder + ); } /** @@ -283,6 +306,8 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject))); } + $this->performAdditionalCreateAction($createdObject); + // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl()); @@ -317,7 +342,7 @@ abstract class AbstractCrudController extends BaseAdminController if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response; // Load the object - $object = $this->getExistingObject($this->getRequest()); + $object = $this->getExistingObject(); if ($object != null) { @@ -368,6 +393,8 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject))); } + $this->performAdditionalUpdateAction($changedObject); + // If we have to stay on the same page, do not redirect to the succesUrl, // just redirect to the edit page again. if ($this->getRequest()->get('save_mode') == 'stay') { @@ -467,6 +494,7 @@ abstract class AbstractCrudController extends BaseAdminController $this->adminLogAppend( sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject))); } + $this->performAdditionalDeleteAction($deletedObject); $this->redirectToListTemplate(); } diff --git a/core/lib/Thelia/Controller/Admin/AttributeAvController.php b/core/lib/Thelia/Controller/Admin/AttributeAvController.php index b7118b53a..b3afa687d 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeAvController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeAvController.php @@ -39,10 +39,12 @@ use Thelia\Core\Event\UpdatePositionEvent; */ class AttributeAvController extends AbstractCrudController { - public function __construct() { + public function __construct() + { parent::__construct( - 'attribute', + 'attributeav', 'manual', + 'order', 'admin.configuration.attributes-av.view', 'admin.configuration.attributes-av.create', @@ -57,15 +59,18 @@ class AttributeAvController extends AbstractCrudController ); } - protected function getCreationForm() { + protected function getCreationForm() + { return new AttributeAvCreationForm($this->getRequest()); } - protected function getUpdateForm() { + protected function getUpdateForm() + { return new AttributeAvModificationForm($this->getRequest()); } - protected function getCreationEvent($formData) { + protected function getCreationEvent($formData) + { $createEvent = new AttributeAvCreateEvent(); $createEvent @@ -77,8 +82,8 @@ class AttributeAvController extends AbstractCrudController return $createEvent; } - protected function getUpdateEvent($formData) { - + protected function getUpdateEvent($formData) + { $changeEvent = new AttributeAvUpdateEvent($formData['id']); // Create and dispatch the change event @@ -93,8 +98,8 @@ class AttributeAvController extends AbstractCrudController return $changeEvent; } - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { - + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { return new UpdatePositionEvent( $this->getRequest()->get('attributeav_id', null), $positionChangeMode, @@ -102,16 +107,18 @@ class AttributeAvController extends AbstractCrudController ); } - protected function getDeleteEvent() { + protected function getDeleteEvent() + { return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id')); } - protected function eventContainsObject($event) { + protected function eventContainsObject($event) + { return $event->hasAttributeAv(); } - protected function hydrateObjectForm($object) { - + protected function hydrateObjectForm($object) + { $data = array( 'id' => $object->getId(), 'locale' => $object->getLocale(), @@ -125,32 +132,38 @@ class AttributeAvController extends AbstractCrudController return new AttributeAvModificationForm($this->getRequest(), "form", $data); } - protected function getObjectFromEvent($event) { + protected function getObjectFromEvent($event) + { return $event->hasAttributeAv() ? $event->getAttributeAv() : null; } - protected function getExistingObject() { + protected function getExistingObject() + { return AttributeAvQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) ->findOneById($this->getRequest()->get('attributeav_id')); } - protected function getObjectLabel($object) { + protected function getObjectLabel($object) + { return $object->getTitle(); } - protected function getObjectId($object) { + protected function getObjectId($object) + { return $object->getId(); } - protected function getViewArguments() { + protected function getViewArguments() + { return array( 'attribute_id' => $this->getRequest()->get('attribute_id'), 'order' => $this->getCurrentListOrder() ); } - protected function renderListTemplate($currentOrder) { + protected function renderListTemplate($currentOrder) + { // We always return to the attribute edition form return $this->render( 'attribute-edit', @@ -158,12 +171,14 @@ class AttributeAvController extends AbstractCrudController ); } - protected function renderEditionTemplate() { + protected function renderEditionTemplate() + { // We always return to the attribute edition form return $this->render('attribute-edit', $this->getViewArguments()); } - protected function redirectToEditionTemplate() { + protected function redirectToEditionTemplate() + { // We always return to the attribute edition form $this->redirectToRoute( "admin.configuration.attributes.update", @@ -171,7 +186,8 @@ class AttributeAvController extends AbstractCrudController ); } - protected function redirectToListTemplate() { + protected function redirectToListTemplate() + { $this->redirectToRoute( "admin.configuration.attributes.update", $this->getViewArguments() diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index f6b76c0df..0ae181900 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -31,6 +31,10 @@ use Thelia\Model\AttributeQuery; use Thelia\Form\AttributeModificationForm; use Thelia\Form\AttributeCreationForm; use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Model\AttributeAv; +use Thelia\Model\AttributeAvQuery; +use Thelia\Core\Event\AttributeAvUpdateEvent; +use Thelia\Core\Event\AttributeEvent; /** * Manages attributes sent by mail @@ -39,10 +43,12 @@ use Thelia\Core\Event\UpdatePositionEvent; */ class AttributeController extends AbstractCrudController { - public function __construct() { + public function __construct() + { parent::__construct( 'attribute', 'manual', + 'order', 'admin.configuration.attributes.view', 'admin.configuration.attributes.create', @@ -57,15 +63,18 @@ class AttributeController extends AbstractCrudController ); } - protected function getCreationForm() { + protected function getCreationForm() + { return new AttributeCreationForm($this->getRequest()); } - protected function getUpdateForm() { + protected function getUpdateForm() + { return new AttributeModificationForm($this->getRequest()); } - protected function getCreationEvent($formData) { + protected function getCreationEvent($formData) + { $createEvent = new AttributeCreateEvent(); $createEvent @@ -77,8 +86,8 @@ class AttributeController extends AbstractCrudController return $createEvent; } - protected function getUpdateEvent($formData) { - + protected function getUpdateEvent($formData) + { $changeEvent = new AttributeUpdateEvent($formData['id']); // Create and dispatch the change event @@ -93,8 +102,31 @@ class AttributeController extends AbstractCrudController return $changeEvent; } - protected function createUpdatePositionEvent($positionChangeMode, $positionValue) { + /** + * Process the attributes values (fix it in future version to integrate it in the attribute form as a collection) + * + * @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction() + */ + protected function performAdditionalUpdateAction($updatedObject) + { + $attr_values = $this->getRequest()->get('attribute_values', null); + if ($attr_values !== null) { + + foreach($attr_values as $id => $value) { + + $event = new AttributeAvUpdateEvent($id); + + $event->setTitle($value); + $event->setLocale($this->getCurrentEditionLocale()); + + $this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event); + } + } + } + + protected function createUpdatePositionEvent($positionChangeMode, $positionValue) + { return new UpdatePositionEvent( $this->getRequest()->get('attribute_id', null), $positionChangeMode, @@ -102,15 +134,18 @@ class AttributeController extends AbstractCrudController ); } - protected function getDeleteEvent() { + protected function getDeleteEvent() + { return new AttributeDeleteEvent($this->getRequest()->get('attribute_id')); } - protected function eventContainsObject($event) { + protected function eventContainsObject($event) + { return $event->hasAttribute(); } - protected function hydrateObjectForm($object) { + protected function hydrateObjectForm($object) + { $data = array( 'id' => $object->getId(), @@ -121,44 +156,132 @@ class AttributeController extends AbstractCrudController 'postscriptum' => $object->getPostscriptum() ); + // Setup attributes values + /* + * FIXME : doesn't work. "We get a This form should not contain extra fields." error + $attr_av_list = AttributeAvQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->filterByAttributeId($object->getId()) + ->find(); + + $attr_array = array(); + + foreach($attr_av_list as $attr_av) { + $attr_array[$attr_av->getId()] = $attr_av->getTitle(); + } + + $data['attribute_values'] = $attr_array; + */ + // Setup the object form return new AttributeModificationForm($this->getRequest(), "form", $data); } - protected function getObjectFromEvent($event) { + protected function getObjectFromEvent($event) + { return $event->hasAttribute() ? $event->getAttribute() : null; } - protected function getExistingObject() { + protected function getExistingObject() + { return AttributeQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) ->findOneById($this->getRequest()->get('attribute_id')); } - protected function getObjectLabel($object) { + protected function getObjectLabel($object) + { return $object->getTitle(); } - protected function getObjectId($object) { + protected function getObjectId($object) + { return $object->getId(); } - protected function renderListTemplate($currentOrder) { + protected function renderListTemplate($currentOrder) + { return $this->render('attributes', array('order' => $currentOrder)); } - protected function renderEditionTemplate() { - return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id'))); - } - - protected function redirectToEditionTemplate() { - $this->redirectToRoute( - "admin.configuration.attributes.update", - array('attribute_id' => $this->getRequest()->get('attribute_id')) + protected function renderEditionTemplate() + { + return $this->render( + 'attribute-edit', + array( + 'attribute_id' => $this->getRequest()->get('attribute_id'), + 'attributeav_order' => $this->getAttributeAvListOrder() + ) ); } - protected function redirectToListTemplate() { + protected function redirectToEditionTemplate() + { + $this->redirectToRoute( + "admin.configuration.attributes.update", + array( + 'attribute_id' => $this->getRequest()->get('attribute_id'), + 'attributeav_order' => $this->getAttributeAvListOrder() + ) + ); + } + + protected function redirectToListTemplate() + { $this->redirectToRoute('admin.configuration.attributes.default'); } + + /** + * Get the Attribute value list order. + * + * @return string the current list order + */ + protected function getAttributeAvListOrder() + { + return $this->getListOrderFromSession( + 'attributeav', + 'attributeav_order', + 'manual' + ); + } + + /** + * Add or Remove from all product templates + */ + protected function addRemoveFromAllTemplates($eventType) + { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response; + + try { + if (null !== $object = $this->getExistingObject()) { + + $event = new AttributeEvent($object); + + $this->dispatch($eventType, $event); + } + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToListTemplate(); + } + + /** + * Remove from all product templates + */ + public function removeFromAllTemplates() + { + return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES); + } + + /** + * Add to all product templates + */ + public function addToAllTemplates() + { + return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 4fb8bf31e..6471dda81 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -97,7 +97,7 @@ class BaseAdminController extends BaseController protected function errorPage($message) { if ($message instanceof \Exception) { - $message = sprintf($this->getTranslator()->trans("Sorry, an error occured: %msg"), array('msg' => $message->getMessage())); + $message = $this->getTranslator()->trans("Sorry, an error occured: %msg", array('%msg' => $message->getMessage())); } return $this->render('general_error', array( @@ -273,6 +273,35 @@ class BaseAdminController extends BaseController return $this->getCurrentEditionLang()->getLocale(); } + + /** + * Return the current list order identifier for a given object name, + * updating in using the current request. + * + * @param unknown $objectName the object name (e.g. 'attribute', 'message') + * @param unknown $requestParameterName the name of the request parameter that defines the list order + * @param unknown $defaultListOrder the default order to use, if none is defined + * @param string $updateSession if true, the session will be updated with the current order. + * + * @return String the current liste order. + */ + protected function getListOrderFromSession($objectName, $requestParameterName, $defaultListOrder, $updateSession = true) { + + $order = $defaultListOrder; + + $orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $objectName); + + // Find the current order + $order = $this->getRequest()->get( + $requestParameterName, + $this->getSession()->get($orderSessionIdentifier, $defaultListOrder) + ); + + if ($updateSession) $this->getSession()->set($orderSessionIdentifier, $order); + + return $order; + } + /** * Render the given template, and returns the result as an Http Response. * @@ -314,7 +343,7 @@ class BaseAdminController extends BaseController 'edit_language_id' => $edition_language->getId(), 'edit_language_locale' => $edition_language->getLocale(), - 'current_url' => htmlspecialchars($this->getRequest()->getUri()) + 'current_url' => $this->getRequest()->getUri() )); // Update the current edition language in session diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index ee88e99e0..ff0e4bb39 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -43,6 +43,7 @@ class ConfigController extends AbstractCrudController parent::__construct( 'variable', 'name', + 'order', 'admin.configuration.variables.view', 'admin.configuration.variables.create', diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 2df950984..4f3fdaaea 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -43,6 +43,7 @@ class CurrencyController extends AbstractCrudController parent::__construct( 'currency', 'manual', + 'order', 'admin.configuration.currencies.view', 'admin.configuration.currencies.create', diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index f87218116..a55c9deca 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -37,10 +37,12 @@ use Thelia\Form\MessageCreationForm; */ class MessageController extends AbstractCrudController { - public function __construct() { + public function __construct() + { parent::__construct( 'message', - null, + null, // no sort order change + null, // no sort order change 'admin.configuration.messages.view', 'admin.configuration.messages.create', @@ -55,15 +57,18 @@ class MessageController extends AbstractCrudController ); } - protected function getCreationForm() { + protected function getCreationForm() + { return new MessageCreationForm($this->getRequest()); } - protected function getUpdateForm() { + protected function getUpdateForm() + { return new MessageModificationForm($this->getRequest()); } - protected function getCreationEvent($formData) { + protected function getCreationEvent($formData) + { $createEvent = new MessageCreateEvent(); $createEvent @@ -76,7 +81,8 @@ class MessageController extends AbstractCrudController return $createEvent; } - protected function getUpdateEvent($formData) { + protected function getUpdateEvent($formData) + { $changeEvent = new MessageUpdateEvent($formData['id']); // Create and dispatch the change event @@ -93,16 +99,18 @@ class MessageController extends AbstractCrudController return $changeEvent; } - protected function getDeleteEvent() { + protected function getDeleteEvent() + { return new MessageDeleteEvent($this->getRequest()->get('message_id')); } - protected function eventContainsObject($event) { + protected function eventContainsObject($event) + { return $event->hasMessage(); } - protected function hydrateObjectForm($object) { - + protected function hydrateObjectForm($object) + { // Prepare the data that will hydrate the form $data = array( 'id' => $object->getId(), @@ -119,40 +127,48 @@ class MessageController extends AbstractCrudController return new MessageModificationForm($this->getRequest(), "form", $data); } - protected function getObjectFromEvent($event) { + protected function getObjectFromEvent($event) + { return $event->hasMessage() ? $event->getMessage() : null; } - protected function getExistingObject() { + protected function getExistingObject() + { return MessageQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) ->findOneById($this->getRequest()->get('message_id')); } - protected function getObjectLabel($object) { + protected function getObjectLabel($object) + { return $object->getName(); } - protected function getObjectId($object) { + protected function getObjectId($object) + { return $object->getId(); } - protected function renderListTemplate($currentOrder) { + protected function renderListTemplate($currentOrder) + { return $this->render('messages'); } - protected function renderEditionTemplate() { + protected function renderEditionTemplate() + { return $this->render('message-edit', array('message_id' => $this->getRequest()->get('message_id'))); } - protected function redirectToEditionTemplate() { + protected function redirectToEditionTemplate() + { $this->redirectToRoute( "admin.configuration.messages.update", array('message_id' => $this->getRequest()->get('message_id')) ); } - protected function redirectToListTemplate() { + protected function redirectToListTemplate() + { $this->redirectToRoute('admin.configuration.messages.default'); } } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 78d84b758..97e140eb6 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -369,6 +369,9 @@ final class TheliaEvents const ATTRIBUTE_DELETE = "action.deleteAttribute"; const ATTRIBUTE_UPDATE_POSITION = "action.updateAttributePosition"; + const ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES = "action.addAttributeToAllTemplate"; + const ATTRIBUTE_ADD_TO_ALL_TEMPLATES = "action.removeAttributeFromAllTemplate"; + const BEFORE_CREATEATTRIBUTE = "action.before_createAttribute"; const AFTER_CREATEATTRIBUTE = "action.after_createAttribute"; diff --git a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php index 1d94e889e..e9a7d9eb8 100755 --- a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php +++ b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php @@ -59,7 +59,7 @@ class AttributeAvailability extends BaseI18nLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse')) + new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse')) ), 'manual' ) @@ -100,6 +100,12 @@ class AttributeAvailability extends BaseI18nLoop foreach ($orders as $order) { switch ($order) { + case 'id': + $search->orderById(Criteria::ASC); + break; + case 'id_reverse': + $search->orderById(Criteria::DESC); + break; case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index 5608fc168..a56bbff1c 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -106,6 +106,9 @@ class AdminUtilities extends AbstractSmartyPlugin // The column label $label = $this->getParam($params, 'label'); + // The request parameter + $request_parameter_name = $this->getParam($params, 'request_parameter_name', 'order'); + if ($current_order == $order) { $icon = 'up'; $order_change = $reverse_order; @@ -121,7 +124,7 @@ class AdminUtilities extends AbstractSmartyPlugin else $output = ''; - return sprintf('%s%s', $output, URL::getInstance()->absoluteUrl($path, array('order' => $order_change)), $label); + return sprintf('%s%s', $output, URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), $label); } /** diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 9ae840019..2d5324644 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -112,6 +112,37 @@ class Form extends AbstractSmartyPlugin } } + protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars) + { + $template->assign("name", $fieldName); + + $template->assign("value", $fieldValue); + + // If Checkbox input type + if ($fieldVars['checked'] !== null) { + $this->renderFormFieldCheckBox($template, $formFieldView['checked']); + } + + $template->assign("label", $fieldVars["label"]); + $template->assign("label_attr", $fieldVars["label_attr"]); + + $errors = $fieldVars["errors"]; + + $template->assign("error", empty($errors) ? false : true); + + if (! empty($errors)) { + $this->assignFieldErrorVars($template, $errors); + } + + $attr = array(); + + foreach ($fieldVars["attr"] as $key => $value) { + $attr[] = sprintf('%s="%s"', $key, $value); + } + + $template->assign("attr", implode(" ", $attr)); + } + public function renderFormField($params, $content, \Smarty_Internal_Template $template, &$repeat) { if ($repeat) { @@ -120,32 +151,29 @@ class Form extends AbstractSmartyPlugin $template->assign("options", $formFieldView->vars); - $template->assign("name", $formFieldView->vars["full_name"]); - $template->assign("value", $formFieldView->vars["value"]); + $value = $formFieldView->vars["value"]; +/* FIXME: doesnt work. We got "This form should not contain extra fields." error. + // We have a collection + if (is_array($value)) { - // If Checkbox input type - if ($formFieldView->vars['checked'] !== null) { - $this->renderFormFieldCheckBox($template, $formFieldView); + $key = $this->getParam($params, 'value_key'); + + if ($key != null) { + + if (isset($value[$key])) { + + $name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key); + $val = $value[$key]; + + $this->assignFieldValues($template, $name, $val, $formFieldView->vars); + } + } } - - $template->assign("label", $formFieldView->vars["label"]); - $template->assign("label_attr", $formFieldView->vars["label_attr"]); - - $errors = $formFieldView->vars["errors"]; - - $template->assign("error", empty($errors) ? false : true); - - if (! empty($errors)) { - $this->assignFieldErrorVars($template, $errors); + else { + $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars); } - - $attr = array(); - - foreach ($formFieldView->vars["attr"] as $key => $value) { - $attr[] = sprintf('%s="%s"', $key, $value); - } - - $template->assign("attr", implode(" ", $attr)); +*/ + $this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars); $formFieldView->setRendered(); } else { @@ -275,12 +303,12 @@ class Form extends AbstractSmartyPlugin * @param \Smarty_Internal_Template $template * @param $formFieldView */ - public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $formFieldView) + public function renderFormFieldCheckBox(\Smarty_Internal_Template $template, $isChecked) { $template->assign("value", 0); - if ($formFieldView->vars['checked']) { + if ($isChecked) { $template->assign("value", 1); } - $template->assign("value", $formFieldView->vars['checked']); + $template->assign("value", $isChecked); } } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index 905c5bb5b..56c853d00 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -54,6 +54,7 @@ class UrlGenerator extends AbstractSmartyPlugin $url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target'))); if ($target != null) $url .= '#'.$target; + return $url; } diff --git a/core/lib/Thelia/Form/AttributeModificationForm.php b/core/lib/Thelia/Form/AttributeModificationForm.php index 62b0b707a..45dab7b28 100644 --- a/core/lib/Thelia/Form/AttributeModificationForm.php +++ b/core/lib/Thelia/Form/AttributeModificationForm.php @@ -43,10 +43,12 @@ class AttributeModificationForm extends AttributeCreationForm ) ) )) +/* FIXME: doesn't work ->add('attribute_values', 'collection', array( 'type' => 'text', 'options' => array('required' => false) )) +*/ ; // Add standard description fields From 275b20ac7751e2330fc0816e45d51453a01a49b6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 10:17:45 +0200 Subject: [PATCH 06/10] allow to make an address as default on update action --- core/lib/Thelia/Action/Address.php | 4 ++++ .../Thelia/Config/Resources/routing/front.xml | 7 ++++++- .../Controller/Front/AddressController.php | 18 +++++++----------- .../Controller/Front/BaseFrontController.php | 7 +++++++ .../Core/Event/AddressCreateOrUpdateEvent.php | 18 +++++++++++++++++- core/lib/Thelia/Form/AddressCreateForm.php | 10 ++++++++-- core/lib/Thelia/Model/Address.php | 14 ++++++++++++++ templates/default/account.html | 3 ++- templates/default/register.html | 4 ++-- 9 files changed, 67 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 278f71a5b..27d46a4b7 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -73,6 +73,10 @@ class Address extends BaseAction implements EventSubscriberInterface ->save() ; + if($event->getIsDefault()) { + $addressModel->makeItDefault(); + } + $event->setAddress($addressModel); } diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index c50fd97b9..c30e576b9 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -59,7 +59,12 @@ - + + Thelia\Controller\Front\DefaultController::noAction + address + + + Thelia\Controller\Front\AddressController::createAction address diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index 5f3fb4799..c4a40d951 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -46,14 +46,13 @@ class AddressController extends BaseFrontController */ public function generateModalAction($address_id) { - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->accessDenied(); - } - + $this->checkAuth(); $this->checkXmlHttpRequest(); } + + /** * Create controller. * Check if customer is logged in @@ -62,9 +61,7 @@ class AddressController extends BaseFrontController */ public function createAction() { - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->accessDenied() - } + $this->checkAuth(); $addressCreate = new AddressCreateForm($this->getRequest()); @@ -98,11 +95,9 @@ class AddressController extends BaseFrontController public function updateAction() { + $this->checkAuth(); $request = $this->getRequest(); - if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->redirectToRoute("home"); - } if (null === $address_id = $request->get("address_id")) { $this->redirectToRoute("home"); @@ -164,7 +159,8 @@ class AddressController extends BaseFrontController $form->get("country")->getData(), $form->get("cellphone")->getData(), $form->get("phone")->getData(), - $form->get("company")->getData() + $form->get("company")->getData(), + $form->get("is_default")->getData() ); } } diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index cf83e865d..1c4a13977 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -50,4 +50,11 @@ class BaseFrontController extends BaseController { $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId, array(), $referenceType), $urlParameters)); } + + public function checkAuth() + { + if($this->getSecurityContext()->hasCustomerUser() === false) { + $this->redirectToRoute("customer.login.view"); + } + } } diff --git a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php index af69ae0b4..01e615ff6 100644 --- a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php @@ -108,7 +108,12 @@ class AddressCreateOrUpdateEvent extends ActionEvent */ protected $address; - public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company) + /** + * @var int + */ + protected $isDefault; + + public function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company, $isDefault = 0) { $this->address1 = $address1; $this->address2 = $address2; @@ -123,6 +128,7 @@ class AddressCreateOrUpdateEvent extends ActionEvent $this->phone = $phone; $this->title = $title; $this->zipcode = $zipcode; + $this->isDefault = $isDefault; } /** @@ -229,6 +235,16 @@ class AddressCreateOrUpdateEvent extends ActionEvent return $this->zipcode; } + /** + * @return int + */ + public function getIsDefault() + { + return $this->isDefault; + } + + + /** * @param \Thelia\Model\Customer $customer */ diff --git a/core/lib/Thelia/Form/AddressCreateForm.php b/core/lib/Thelia/Form/AddressCreateForm.php index ed1750047..483366a1f 100644 --- a/core/lib/Thelia/Form/AddressCreateForm.php +++ b/core/lib/Thelia/Form/AddressCreateForm.php @@ -60,7 +60,7 @@ class AddressCreateForm extends BaseForm "constraints" => array( new NotBlank() ), - "label" => Translator::getInstance()->trans("Address label *"), + "label" => Translator::getInstance()->trans("Address label"), "label_attr" => array( "for" => "label_create" ), @@ -154,11 +154,17 @@ class AddressCreateForm extends BaseForm ) )) ->add("company", "text", array( - "label" => Translator::getInstance()->trans("Compagny"), + "label" => Translator::getInstance()->trans("Company"), "label_attr" => array( "for" => "company_create" ) )) + ->add("is_default", "integer", array( + "label" => Translator::getInstance()->trans("Make this address has my primary address"), + "label_attr" => array( + "for" => "default_address" + ) + )) ; } diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index dbd334ba2..9c2a390b5 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -7,10 +7,24 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Address as BaseAddress; +use Thelia\Model\AddressQuery; class Address extends BaseAddress { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + /** + * put the the current address as default one + */ + public function makeItDefault() + { + + AddressQuery::create()->filterByCustomerId($this->getCustomerId()) + ->update(array('isDefault' => '0')); + + $this->setIsDefault(1); + $this->save(); + } + /** * Code to be run before inserting to database * @param ConnectionInterface $con diff --git a/templates/default/account.html b/templates/default/account.html index c7edeb449..b67d6424c 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -1,3 +1,4 @@ +{check_auth context="front" roles="CUSTOMER" login_tpl="login"} {extends file="layout.tpl"} {block name="breadcrumb"} @@ -74,7 +75,7 @@
- {intl l="Add a new address"} + {intl l="Add a new address"} {loop type="address" name="customer.addresses"} diff --git a/templates/default/register.html b/templates/default/register.html index 7100737bc..a3448932b 100644 --- a/templates/default/register.html +++ b/templates/default/register.html @@ -96,7 +96,7 @@
- + {if $error } {$message} {elseif $value != "" && !$error} @@ -109,7 +109,7 @@
- + {if $error } {$message} {elseif $value != "" && !$error} From 2d8656e45b0dea6aa8254285e8d601faa1556f16 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 10:55:45 +0200 Subject: [PATCH 07/10] allow to create a new address --- core/lib/Thelia/Action/Address.php | 58 ++++--- core/lib/Thelia/Model/Address.php | 2 +- templates/default/address.html | 247 +++++++++++++++++++++++++++++ 3 files changed, 283 insertions(+), 24 deletions(-) create mode 100644 templates/default/address.html diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 27d46a4b7..0aee9a6f5 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -22,10 +22,13 @@ /*************************************************************************************/ namespace Thelia\Action; +use Propel\Runtime\Exception\PropelException; +use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\AddressCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Address as AddressModel; +use Thelia\Model\Map\AddressTableMap; /** * Class Address @@ -52,32 +55,41 @@ class Address extends BaseAction implements EventSubscriberInterface protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) { $addressModel->setDispatcher($this->getDispatcher()); + $con = Propel::getWriteConnection(AddressTableMap::DATABASE_NAME); + $con->beginTransaction(); + try { + if ($addressModel->isNew()) { + $addressModel->setLabel($event->getLabel()); + } - if ($addressModel->isNew()) { - $addressModel->setLabel($event->getLabel()); + $addressModel + ->setTitleId($event->getTitle()) + ->setFirstname($event->getFirstname()) + ->setLastname($event->getLastname()) + ->setAddress1($event->getAddress1()) + ->setAddress2($event->getAddress2()) + ->setAddress3($event->getAddress3()) + ->setZipcode($event->getZipcode()) + ->setCity($event->getCity()) + ->setCountryId($event->getCountry()) + ->setCellphone($event->getCellphone()) + ->setPhone($event->getPhone()) + ->setCompany($event->getCompany()) + ->save() + ; + + if($event->getIsDefault()) { + $addressModel->makeItDefault(); + } + + $event->setAddress($addressModel); + $con->commit(); + + } catch(PropelException $e) { + $con->rollback(); + throw $e; } - $addressModel - ->setTitleId($event->getTitle()) - ->setFirstname($event->getFirstname()) - ->setLastname($event->getLastname()) - ->setAddress1($event->getAddress1()) - ->setAddress2($event->getAddress2()) - ->setAddress3($event->getAddress3()) - ->setZipcode($event->getZipcode()) - ->setCity($event->getCity()) - ->setCountryId($event->getCountry()) - ->setCellphone($event->getCellphone()) - ->setPhone($event->getPhone()) - ->setCompany($event->getCompany()) - ->save() - ; - - if($event->getIsDefault()) { - $addressModel->makeItDefault(); - } - - $event->setAddress($addressModel); } /** diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index 9c2a390b5..8c9bd4552 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -19,7 +19,7 @@ class Address extends BaseAddress { { AddressQuery::create()->filterByCustomerId($this->getCustomerId()) - ->update(array('isDefault' => '0')); + ->update(array('IsDefault' => '0')); $this->setIsDefault(1); $this->save(); diff --git a/templates/default/address.html b/templates/default/address.html new file mode 100644 index 000000000..086a2b5ba --- /dev/null +++ b/templates/default/address.html @@ -0,0 +1,247 @@ +{check_auth context="front" roles="CUSTOMER" login_tpl="login"} +{extends file="layout.tpl"} + +{block name="breadcrumb"} + +{/block} + +{block name="main-content"} +
+ +
+ +

{intl l="Create New Address"}

+ {form name="thelia.address.create"} +
+ {form_field form=$form field='success_url'} + {* the url the user is redirected to on login success *} + {/form_field} + + {form_field form=$form field='error_message'} + {* the url the user is redirected to on login success *} + {/form_field} + {form_hidden_fields form=$form} + {if $form_error}
{$form_error_message}
{/if} +
+
+ {intl l="Address"} +
+ +
+ {form_field form=$form field="label"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="title"} +
+ +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + + {form_field form=$form field="firstname"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + + {form_field form=$form field="lastname"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="address1"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="address2"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="zipcode"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="city"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="country"} +
+ +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ {/form_field} + + {form_field form=$form field="phone"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} + + {form_field form=$form field="cellphone"} +
+ + +
+ + {if $error } + {$message} + {elseif $value != "" && !$error} + + {/if} +
+
+ + {/form_field} +
+
+ + {form_field form=$form field="is_default"} +
+
+
+ +
+
+
+ + {/form_field} + +
+
+ +
+
+ + + {/form} +
+ +
+{/block} \ No newline at end of file From ddf175f361542c335ed84b109c1445403a099771 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 11:31:12 +0200 Subject: [PATCH 08/10] allow update customer address in front tempalte --- .../Thelia/Config/Resources/routing/front.xml | 11 +- .../Controller/Front/AddressController.php | 26 +- templates/default/account.html | 2 +- templates/default/address-update.html | 250 ++++++++++++++++++ templates/default/address.html | 4 +- 5 files changed, 277 insertions(+), 16 deletions(-) create mode 100644 templates/default/address-update.html diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index c30e576b9..da3c1bdb7 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -69,13 +69,14 @@ address - - Thelia\Controller\Front\DefaultController::noAction - address-edit + + Thelia\Controller\Front\AddressController::updateViewAction + address-update - - Thelia\Controller\Front\AddressController::updateAction + + Thelia\Controller\Front\AddressController::processUpdateAction + address-update diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index c4a40d951..33fa67069 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -27,7 +27,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Form\AddressCreateForm; use Thelia\Form\AddressUpdateForm; use Thelia\Form\Exception\FormValidationException; -use Thelia\Model\Base\AddressQuery; +use Thelia\Model\AddressQuery; use Thelia\Model\Customer; use Thelia\Tools\URL; @@ -93,18 +93,28 @@ class AddressController extends BaseFrontController } } - public function updateAction() + public function updateViewAction($address_id) + { + $this->checkAuth(); + + $customer = $this->getSecurityContext()->getCustomerUser(); + $address = AddressQuery::create()->findPk($address_id); + + if(!$address || $customer->getId() != $address->getCustomerId()) { + $this->redirectToRoute("home"); + } + + $this->getParserContext()->set("address_id", $address_id); + } + + public function processUpdateAction($address_id) { $this->checkAuth(); $request = $this->getRequest(); - - if (null === $address_id = $request->get("address_id")) { - $this->redirectToRoute("home"); - } - $addressUpdate = new AddressUpdateForm($request); + try { $customer = $this->getSecurityContext()->getCustomerUser(); @@ -131,7 +141,7 @@ class AddressController extends BaseFrontController } catch (\Exception $e) { $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); } - + $this->getParserContext()->set("address_id", $address_id); if ($message !== false) { \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message)); diff --git a/templates/default/account.html b/templates/default/account.html index b67d6424c..f3815e5c0 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -114,7 +114,7 @@
{/loop} + + + + + {/ifloop}
@@ -110,34 +142,6 @@ {module_include location='customer_bottom'} -
-
- -
    - {if $customer_page != 1} -
  • «
  • - {else} -
  • «
  • - {/if} - - {pageloop rel="customer_list"} - {if $PAGE != $CURRENT} -
  • {$PAGE}
  • - - {else} -
  • {$PAGE}
  • - {/if} - - {if $PAGE == $LAST && $LAST != $CURRENT} -
  • »
  • - {else} -
  • »
  • - {/if} - {/pageloop} -
- -
-
{* Adding a new Category *} From 8367863b489de325ec04794bd5aecf59b71e417e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 13 Sep 2013 12:33:13 +0200 Subject: [PATCH 10/10] allow address removal from front --- core/lib/Thelia/Action/Address.php | 11 +++++- .../Thelia/Config/Resources/routing/front.xml | 5 +++ .../Controller/Front/AddressController.php | 17 ++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 5 +++ templates/default/account.html | 39 +++++++++++++++++-- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 0aee9a6f5..a912888c8 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -26,6 +26,7 @@ use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Address as AddressModel; use Thelia\Model\Map\AddressTableMap; @@ -52,6 +53,13 @@ class Address extends BaseAction implements EventSubscriberInterface $this->createOrUpdate($addressModel, $event); } + public function delete(AddressEvent $event) + { + $address = $event->getAddress(); + + $address->delete(); + } + protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) { $addressModel->setDispatcher($this->getDispatcher()); @@ -116,7 +124,8 @@ class Address extends BaseAction implements EventSubscriberInterface { return array( TheliaEvents::ADDRESS_CREATE => array("create", 128), - TheliaEvents::ADDRESS_UPDATE => array("update", 128) + TheliaEvents::ADDRESS_UPDATE => array("update", 128), + TheliaEvents::ADDRESS_DELETE => array("delete", 128) ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index da3c1bdb7..38afb7d7f 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -79,6 +79,11 @@ address-update + + Thelia\Controller\Front\AddressController::deleteAction + account + + Thelia\Controller\Front\AddressController::generateModalAction modal-address diff --git a/core/lib/Thelia/Controller/Front/AddressController.php b/core/lib/Thelia/Controller/Front/AddressController.php index 33fa67069..272fa6424 100644 --- a/core/lib/Thelia/Controller/Front/AddressController.php +++ b/core/lib/Thelia/Controller/Front/AddressController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Front; use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\AddressCreateForm; use Thelia\Form\AddressUpdateForm; @@ -154,6 +155,22 @@ class AddressController extends BaseFrontController } } + public function deleteAction($address_id) + { + $this->checkAuth(); + + $customer = $this->getSecurityContext()->getCustomerUser(); + $address = AddressQuery::create()->findPk($address_id); + + if(!$address || $customer->getId() != $address->getCustomerId()) { + $this->redirectToRoute("home"); + } + + $this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address)); + + $this->redirectToRoute("customer.account.view"); + } + protected function createAddressEvent($form) { return new AddressCreateOrUpdateEvent( diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 97e140eb6..54f05c0c0 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -129,6 +129,11 @@ final class TheliaEvents */ const ADDRESS_UPDATE = "action.updateAddress"; + /** + * sent on address removal + */ + const ADDRESS_DELETE = "action.deleteAddress"; + const BEFORE_CREATEADDRESS = "action.before_createAddress"; const AFTER_CREATEADDRESS = "action.after_createAddress"; diff --git a/templates/default/account.html b/templates/default/account.html index f3815e5c0..94bd58501 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -78,8 +78,8 @@ {intl l="Add a new address"} - {loop type="address" name="customer.addresses"} - + {loop type="address" name="customer.addresses" customer="current"} + @@ -173,4 +173,37 @@ + + +{/block} + +{block name="after-javascript-include"} + + + {/block} \ No newline at end of file