diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 198c49228..74a645cb9 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -79,7 +79,6 @@ - %kernel.environment% @@ -98,7 +97,7 @@ - + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 313fb3a57..b8796ab16 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -25,14 +25,36 @@ - + - Thelia\Controller\Admin\CategoryController::indexAction + Thelia\Controller\Admin\CategoryController::defaultAction - - Thelia\Controller\Admin\CategoryController::processAction + + + + Thelia\Controller\Admin\CategoryController::createAction + + + + Thelia\Controller\Admin\CategoryController::changeAction + + + + Thelia\Controller\Admin\CategoryController::saveChangeAction + + + + Thelia\Controller\Admin\CategoryController::toggleOnlineAction + + + + Thelia\Controller\Admin\CategoryController::deleteAction + + + + Thelia\Controller\Admin\CategoryController::updatePositionAction diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index eab57394b..15634214c 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -34,6 +34,8 @@ use Thelia\Core\Security\SecurityContext; use Thelia\Model\AdminLog; use Thelia\Model\Lang; use Thelia\Model\LangQuery; +use Thelia\Form\BaseForm; +use Thelia\Form\Exception\FormValidationException; class BaseAdminController extends BaseController { @@ -126,6 +128,55 @@ class BaseAdminController extends BaseController return $response->setContent($this->errorPage("Sorry, you're not allowed to perform this action")); } + /* + * Create the standard message displayed to the user when the form cannot be validated. + */ + protected function createStandardFormValidationErrorMessage(FormValidationException $exception) { + return Translator::getInstance()->trans( + "Please check your input: %error", + array( + '%error' => $exception->getMessage() + ) + ); + } + + /** + * Setup the error context when an error occurs in a action method. + * + * @param string $action the action that caused the error (category modification, variable creation, currency update, etc.) + * @param BaseForm $form the form where the error occured, or null if no form was involved + * @param string $error_message the error message + * @param Exception $exception the exception or null if no exception + */ + protected function setupFormErrorContext($action, $error_message, BaseForm $form = null, \Exception $exception = null) { + + if ($error_message !== false) { + + // Log the error message + Tlog::getInstance()->error( + Translator::getInstance()->trans( + "Error during %action process : %error. Exception was %exc", + array( + '%action' => $action, + '%error' => $error_message, + '%exc' => $exception != null ? $exception->getMessage() : 'no exception' + ) + ) + ); + + if ($fom != null) { + // Mark the form as errored + $form->setErrorMessage($error_message); + + // Pass it to the parser context + $this->getParserContext()->addForm($form); + } + + // Pass the error message to the parser. + $this->getParserContext()->setGeneralError($error_message); + } + } + /** * @return a ParserInterface instance parser */ diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 6cba34e39..73104349c 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -37,223 +37,330 @@ use Thelia\Model\Lang; class CategoryController extends BaseAdminController { - protected function createNewCategory($args) - { - try { - $categoryCreationForm = new CategoryCreationForm($this->getRequest()); + /** + * Render the categories list, ensuring the sort order is set. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + protected function renderList() { - $form = $this->validateForm($categoryCreationForm, "POST"); + $args = $this->setupArgs(); + + return $this->render('categories', $args); + } + + protected function setupArgs() { + + // Get the category ID + $id = $this->getRequest()->get('category_id', 0); + + // Find the current category order + $category_order = $this->getRequest()->get( + 'order', + $this->getSession()->get('admin.category_order', 'manual') + ); + + $args = array( + 'current_category_id' => $id, + 'category_order' => $category_order, + ); + + // Store the current sort order in session + $this->getSession()->set('admin.category_order', $category_order); + + return $args; + } + + /** + * The default action is displaying the categories list. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function defaultAction() { + + if (null !== $response = $this->checkAuth("admin.categories.view")) return $response; + + return $this->renderList(); + } + + protected function createAction($args) + { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.create")) return $response; + + $error_msg = false; + + // Create the Creation Form + $creationForm = new CategoryCreationForm($this->getRequest()); + + try { + + // Validate the form, create the CategoryCreation event and dispatch it. + $form = $this->validateForm($creationForm, "POST"); $data = $form->getData(); + $createEvent = new CategoryCreateEvent(); + $categoryCreateEvent = new CategoryCreateEvent( $data["title"], $data["parent"], $data["locale"] ); - $this->dispatch(TheliaEvents::CATEGORY_CREATE, $categoryCreateEvent); + $this->dispatch(TheliaEvents::CATEGORY_CREATE, $createEvent); - $category = $categoryCreateEvent->getCreatedCategory(); + $createdObject = $createEvent->getCategory(); - $this->adminLogAppend(sprintf("Category %s (ID %s) created", $category->getTitle(), $category->getId())); + // Log currency creation + $this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); - // Substitute _ID_ in the URL with the ID of the created category - $successUrl = str_replace('_ID_', $category->getId(), $categoryCreationForm->getSuccessUrl()); + // Substitute _ID_ in the URL with the ID of the created object + $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); // Redirect to the success URL $this->redirect($successUrl); } - catch (FormValidationException $e) { - $categoryCreationForm->setErrorMessage($e->getMessage()); - $this->getParserContext()->addForm($categoryCreationForm); + catch (FormValidationException $ex) { + // Form cannot be validated + $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); } - catch (Exception $e) { - Tlog::getInstance()->error(sprintf("Failed to create category: %s", $e->getMessage())); - $this->getParserContext()->setGeneralError($e->getMessage()); + catch (\Exception $ex) { + // Any other error + $error_msg = $ex; + } + + if ($error_msg !== false) { + // An error has been detected: log it + Tlog::getInstance()->error(sprintf("Error during category creation process : %s. Exception was %s", $error_msg, $ex->getMessage())); + + // Mark the form as errored + $creationForm->setErrorMessage($error_msg); + + // Pass it to the parser, along with the error currency + $this->getParserContext() + ->addForm($creationForm) + ->setGeneralError($error_msg) + ; } // At this point, the form has error, and should be redisplayed. - return $this->render('categories', $args); + return $this->renderList(); } - protected function editCategory($args) - { - if (null !== $response = $this->checkAuth("admin.category.edit")) return $response; + /** + * Load a currency object for modification, and display the edit template. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function changeAction() { - return $this->render('edit_category', $args); + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + // Load the currency object + $currency = CategoryQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('currency_id')); + + if ($currency != null) { + + // Prepare the data that will hydrate the form + $data = array( + 'id' => $currency->getId(), + 'name' => $currency->getName(), + 'locale' => $currency->getLocale(), + 'code' => $currency->getCode(), + 'symbol' => $currency->getSymbol(), + 'rate' => $currency->getRate() + ); + + // Setup the object form + $changeForm = new CategoryModificationForm($this->getRequest(), "form", $data); + + // Pass it to the parser + $this->getParserContext()->addForm($changeForm); + } + + // Render the edition template. + return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id'))); } - protected function deleteCategory($args) - { + /** + * Save changes on a modified currency object, and either go back to the currency list, or stay on the edition page. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function saveChangeAction() { + + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + $error_msg = false; + + // Create the form from the request + $changeForm = new CategoryModificationForm($this->getRequest()); + + // Get the currency ID + $currency_id = $this->getRequest()->get('currency_id'); + try { - $categoryDeletionForm = new CategoryDeletionForm($this->getRequest()); - $data = $this->validateForm($categoryDeletionForm, "POST")->getData(); + // Check the form against constraints violations + $form = $this->validateForm($changeForm, "POST"); - $categoryDeleteEvent = new CategoryDeleteEvent($data['category_id']); + // Get the form field values + $data = $form->getData(); - $this->dispatch(TheliaEvents::CATEGORY_DELETE, $categoryDeleteEvent); + $changeEvent = new CategoryUpdateEvent($data['id']); - $category = $categoryDeleteEvent->getDeletedCategory(); + // Create and dispatch the change event + $changeEvent + ->setCategoryName($data['name']) + ->setLocale($data["locale"]) + ->setSymbol($data['symbol']) + ->setCode($data['code']) + ->setRate($data['rate']) + ; - $this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $category->getTitle(), $category->getId())); + $this->dispatch(TheliaEvents::CATEGORY_UPDATE, $changeEvent); - // Substitute _ID_ in the URL with the ID of the created category - $successUrl = str_replace('_ID_', $categoryDeleteEvent->getDeletedCategory()->getParent(), $categoryDeletionForm->getSuccessUrl()); + // Log currency modification + $changedObject = $changeEvent->getCategory(); + + $this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); + + // 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') { + $this->redirectToRoute( + "admin.categories.update", + array('currency_id' => $currency_id) + ); + } // Redirect to the success URL - $this->redirect($successUrl); + $this->redirect($changeForm->getSuccessUrl()); } - catch (FormValidationException $e) { - $categoryDeletionForm->setErrorMessage($e->getMessage()); - $this->getParserContext()->addForm($categoryDeletionForm); + catch (FormValidationException $ex) { + // Invalid data entered + $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); } - catch (Exception $e) { - Tlog::getInstance()->error(sprintf("Failed to delete category: %s", $e->getMessage())); - $this->getParserContext()->setGeneralError($e->getMessage()); + catch (\Exception $ex) { + // Any other error + $error_msg = $ex; } - // At this point, something was wrong, category was not deleted. Display parent category list - return $this->render('categories', $args); + if ($error_msg !== false) { + // Log error currency + Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage())); + + // Mark the form as errored + $changeForm->setErrorMessage($error_msg); + + // Pas the form and the error to the parser + $this->getParserContext() + ->addForm($changeForm) + ->setGeneralError($error_msg) + ; + } + + // At this point, the form has errors, and should be redisplayed. + return $this->render('currency-edit', array('currency_id' => $currency_id)); } - protected function browseCategory($args) - { - if (null !== $response = $this->checkAuth("admin.catalog.view")) return $response; + /** + * Sets the default currency + */ + public function setDefaultAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - return $this->render('categories', $args); - } + $changeEvent = new CategoryUpdateEvent($this->getRequest()->get('currency_id', 0)); - protected function visibilityToggle($args) - { - $event = new CategoryToggleVisibilityEvent($this->getRequest()->get('category_id', 0)); - - $this->dispatch(TheliaEvents::CATEGORY_TOGGLE_VISIBILITY, $event); - - return $this->nullResponse(); - } - - protected function changePosition($args) - { - $request = $this->getRequest(); - - $event = new CategoryChangePositionEvent( - $request->get('category_id', 0), - CategoryChangePositionEvent::POSITION_ABSOLUTE, - $request->get('position', null) - ); - - $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); - - return $this->render('categories', $args); - } - - protected function positionDown($args) - { - $event = new CategoryChangePositionEvent( - $this->getRequest()->get('category_id', 0), - CategoryChangePositionEvent::POSITION_DOWN - ); - - $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); - - return $this->render('categories', $args); - } - - protected function positionUp($args) - { - $event = new CategoryChangePositionEvent( - $this->getRequest()->get('category_id', 0), - CategoryChangePositionEvent::POSITION_UP - ); - - $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); - - return $this->render('categories', $args); - } - - public function indexAction() - { - return $this->processAction(); - } - - public function processAction() - { - // Get the current action - $action = $this->getRequest()->get('action', 'browse'); - - // Get the category ID - $id = $this->getRequest()->get('id', 0); - - // Find the current order - $category_order = $this->getRequest()->get( - 'order', - $this->getSession()->get('admin.category_order', 'manual') - ); - - // Find the current edit language ID - $edition_language = $this->getRequest()->get( - 'edition_language', - $this->getSession()->get('admin.edition_language', Lang::getDefaultLanguage()->getId()) - ); - - $args = array( - 'action' => $action, - 'current_category_id' => $id, - 'category_order' => $category_order, - 'edition_language' => $edition_language, - ); - - // Store the current sort order in session - $this->getSession()->set('admin.category_order', $category_order); - - // Store the current edition language in session - $this->getSession()->set('admin.edition_language', $edition_language); + // Create and dispatch the change event + $changeEvent->setIsDefault(true); try { - switch ($action) { - case 'browse' : // Browse categories - - return $this->browseCategory($args); - - case 'create' : // Create a new category - - return $this->createNewCategory($args); - - case 'edit' : // Edit an existing category - - return $this->editCategory($args); - - case 'delete' : // Delete an existing category - - return $this->deleteCategory($args); - - case 'visibilityToggle' : // Toggle visibility - - return $this->visibilityToggle($id); - - case 'changePosition' : // Change position - - return $this->changePosition($args); - - case 'positionUp' : // Move up category - - return $this->positionUp($args); - - case 'positionDown' : // Move down category - - return $this->positionDown($args); - } + $this->dispatch(TheliaEvents::CATEGORY_SET_DEFAULT, $changeEvent); } - catch (AuthorizationException $ex) { - return $this->errorPage($ex->getMessage()); - } - catch (AuthenticationException $ex) { - return $this->errorPage($ex->getMessage()); + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); } - // We did not recognized the action -> return a 404 page - return $this->pageNotFound(); + $this->redirectToRoute('admin.categories.default'); + } + + /** + * Update categories rates + */ + public function updateRatesAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + try { + $this->dispatch(TheliaEvents::CATEGORY_UPDATE_RATES); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToRoute('admin.categories.default'); + } + + /** + * Update currencyposition + */ + public function updatePositionAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + try { + $mode = $this->getRequest()->get('mode', null); + + if ($mode == 'up') + $mode = CategoryUpdatePositionEvent::POSITION_UP; + else if ($mode == 'down') + $mode = CategoryUpdatePositionEvent::POSITION_DOWN; + else + $mode = CategoryUpdatePositionEvent::POSITION_ABSOLUTE; + + $position = $this->getRequest()->get('position', null); + + $event = new CategoryUpdatePositionEvent( + $this->getRequest()->get('currency_id', null), + $mode, + $this->getRequest()->get('position', null) + ); + + $this->dispatch(TheliaEvents::CATEGORY_UPDATE_POSITION, $event); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToRoute('admin.categories.default'); + } + + + /** + * Delete a currency object + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function deleteAction() { + + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.delete")) return $response; + + // Get the currency id, and dispatch the delet request + $event = new CategoryDeleteEvent($this->getRequest()->get('currency_id')); + + $this->dispatch(TheliaEvents::CATEGORY_DELETE, $event); + + $this->redirectToRoute('admin.categories.default'); } } diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index a67ecbaaa..e7d6674b8 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -121,26 +121,14 @@ class ConfigController extends BaseAdminController } catch (FormValidationException $ex) { // Form cannot be validated - $message = sprintf("Please check your input: %s", $ex->getMessage()); + $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = $ex->getMessage(); } - if ($message !== false) { - // An error has been detected: log it - Tlog::getInstance()->error(sprintf("Error during variable creation process : %s. Exception was %s", $message, $ex->getMessage())); - - // Mark the form as errored - $creationForm->setErrorMessage($message); - - // Pass it to the parser, along with the error message - $this->getParserContext() - ->addForm($creationForm) - ->setGeneralError($message) - ; - } + $this->setupFormErrorContext("variable creation", $message, $creationForm, $ex); // At this point, the form has error, and should be redisplayed. return $this->renderList(); @@ -250,27 +238,15 @@ class ConfigController extends BaseAdminController $this->redirect($changeForm->getSuccessUrl()); } catch (FormValidationException $ex) { - // Invalid data entered - $message = sprintf("Please check your input: %s", $ex->getMessage()); + // Form cannot be validated + $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = $ex->getMessage(); } - if ($message !== false) { - // Log error message - Tlog::getInstance()->error(sprintf("Error during variable modification process : %s. Exception was %s", $message, $ex->getMessage())); - - // Mark the form as errored - $changeForm->setErrorMessage($message); - - // Pas the form and the error to the parser - $this->getParserContext() - ->addForm($changeForm) - ->setGeneralError($message) - ; - } + $this->setupFormErrorContext("variable edition", $message, $creationForm, $ex); // At this point, the form has errors, and should be redisplayed. return $this->render('variable-edit', array('variable_id' => $variable_id)); diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 56acfb89d..d5b984cfb 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -111,7 +111,7 @@ class CurrencyController extends BaseAdminController $createdObject = $createEvent->getCurrency(); // Log currency creation - $this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); + $this->adminLogAppend(sprintf("Currency %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); @@ -226,7 +226,7 @@ class CurrencyController extends BaseAdminController // Log currency modification $changedObject = $changeEvent->getCurrency(); - $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); + $this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); // If we have to stay on the same page, do not redirect to the succesUrl, // just redirect to the edit page again. diff --git a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php index f4d5a45ee..1bcfe5f56 100644 --- a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php @@ -25,12 +25,11 @@ namespace Thelia\Core\Event; use Thelia\Model\Category; -class CategoryCreateEvent extends ActionEvent +class CategoryCreateEvent extends CategoryEvent { protected $title; protected $parent; protected $locale; - protected $created_category; public function __construct($title, $parent, $locale) { @@ -68,14 +67,4 @@ class CategoryCreateEvent extends ActionEvent { $this->locale = $locale; } - - public function getCreatedCategory() - { - return $this->created_category; - } - - public function setCreatedCategory(Category $created_category) - { - $this->created_category = $created_category; - } } diff --git a/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php b/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php index 3e863be8e..05253d435 100644 --- a/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php @@ -22,13 +22,11 @@ /*************************************************************************************/ namespace Thelia\Core\Event; + use Thelia\Model\Category; -class CategoryDeleteEvent extends ActionEvent +class CategoryDeleteEvent extends CategoryEvent { - protected $category_id; - protected $deleted_category; - public function __construct($category_id) { $this->category_id = $category_id; @@ -43,14 +41,4 @@ class CategoryDeleteEvent extends ActionEvent { $this->category_id = $category_id; } - - public function getDeletedCategory() - { - return $this->deleted_category; - } - - public function setDeletedCategory(Category $deleted_category) - { - $this->deleted_category = $deleted_category; - } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryEvent.php b/core/lib/Thelia/Core/Event/CategoryEvent.php index c29d681d8..90fbd1e1f 100644 --- a/core/lib/Thelia/Core/Event/CategoryEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryEvent.php @@ -35,13 +35,15 @@ class CategoryEvent extends ActionEvent $this->category = $category; } - /** - * @return \Thelia\Model\Category - */ public function getCategory() { return $this->category; } + public function setCategory(Category $category) + { + $this->category = $category; + return $this; + } } diff --git a/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php b/core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php similarity index 96% rename from core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php rename to core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php index 3a3dbb18f..44af9b946 100644 --- a/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php @@ -23,6 +23,6 @@ namespace Thelia\Core\Event; -class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent +class CategoryUpdatePositionEvent extends BaseUpdatePositionEvent { } \ No newline at end of file diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 20197d9c6..3c0f14808 100755 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -127,6 +127,9 @@ class TheliaHttpKernel extends HttpKernel // See Thelia\Tools\URL class. $this->container->get('thelia.url.manager'); + // Same thing for the Translator service. + $this->container->get('thelia.translator'); + $lang = $this->detectLang($request); if ($lang) { diff --git a/core/lib/Thelia/Core/Translation/Translator.php b/core/lib/Thelia/Core/Translation/Translator.php index 83114d478..d941fefb7 100755 --- a/core/lib/Thelia/Core/Translation/Translator.php +++ b/core/lib/Thelia/Core/Translation/Translator.php @@ -5,6 +5,29 @@ use Symfony\Component\Translation\Translator as BaseTranslator; class Translator extends BaseTranslator { + + protected static $instance = null; + + public function __construct() + { + // Allow singleton style calls once intanciated. + // For this to work, the Translator service has to be instanciated very early. This is done manually + // in TheliaHttpKernel, by calling $this->container->get('thelia.translator'); + self::$instance = $this; + } + + /** + * Return this class instance, only once instanciated. + * + * @throws \RuntimeException if the class has not been instanciated. + * @return Thelia\Core\Translation\Translator the instance. + */ + public static function getInstance() { + if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized."); + + return self::$instance; + } + /** * {@inheritdoc} * @@ -21,7 +44,7 @@ class Translator extends BaseTranslator } if ($this->catalogues[$locale]->has((string) $id, $domain)) - return parent::trans($id, $parameters, $domain = 'messages', $locale = null); + return parent::trans($id, $parameters, $domain, $locale); else return strtr($id, $parameters); } diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 49db025ae..5e3e28018 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -8,9 +8,7 @@
- + {include file="includes/catalog-breadcrumb.html"} {module_include location='catalog_top'} @@ -20,7 +18,7 @@ + + @@ -59,8 +67,8 @@ current_order=$category_order order='visible' reverse_order='visible_reverse' - path={url path='/admin/catalog/category' id="{$current_category_id}"} - label={intl l='Online'} + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='Online'}" } @@ -69,8 +77,8 @@ current_order=$category_order order='manual' reverse_order='manual_reverse' - path={url path='/admin/catalog/category' id="{$current_category_id}"} - label={intl l='Position'} + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='Position'}" } @@ -81,22 +89,24 @@ {loop name="category_list" type="category" visible="*" parent=$current_category_id order=$category_order backend_context="1" lang=$lang_id} + + {module_include location='category_list_row'}
{* display parent category name, and get current cat ID *} - {loop name="category_title" type="category" visible="*" id="{$current_category_id}"} + {loop name="category_title" type="category" visible="*" id=$current_category_id} {intl l="Categories in %cat" cat=$TITLE} {$cat_id = $ID} {/loop} @@ -30,7 +28,7 @@ {module_include location='category_list_caption'} - {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.category.create"} + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} @@ -40,6 +38,16 @@ {ifloop rel="category_list"}
+ {admin_sortable_header + current_order=$category_order + order='id' + reverse_order='id_reverse' + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='ID'}" + } +   @@ -47,8 +55,8 @@ current_order=$category_order order='alpha' reverse_order='alpha_reverse' - path={url path='/admin/catalog/category' id="{$current_category_id}"} - label={intl l='Category title'} + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='Category title'}" }
{$ID} - i={$ID} {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - #TITLE + {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} + #TITLE {/loop} - - {$ID} p={$POSITION} {$TITLE} + + {$TITLE} - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
@@ -111,24 +121,24 @@
{admin_position_block - permission="admin.category.edit" - path={url path='admin/catalog/category' category_id="{$ID}"} + permission="admin.categories.edit" + path={url path='admin/category/update-position' category_id=$ID} url_parameter="category_id" in_place_edit_class="categoryPositionChange" - position="$POSITION" - id="$ID" + position=$POSITION + id=$ID }
- + - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"} - + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"} + {/loop} - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.category.delete"} + {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"} {/loop}
@@ -143,7 +153,7 @@
- {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.category.create"} + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} {intl l="This category has no sub-categories. To create a new one, click the + button above."} {/loop} @@ -166,9 +176,10 @@ + + + @@ -211,8 +241,8 @@ current_order=$product_order order='manual' reverse_order='manual_reverse' - path={url path='/admin/catalog/product' id="{$current_category_id}"} - label={intl l='Position'} + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Position'}" } @@ -221,37 +251,58 @@ - {loop name="product_list" type="product" category="{$current_category_id}" order="manual"} + {loop name="product_list" type="product" category=$current_category_id order="manual"} + + + + + {module_include location='product_list_row'} {/loop} @@ -274,8 +325,105 @@ -{include file="includes/add-category-dialog.html"} -{include file="includes/delete-category-dialog.html"} + {* Adding a new Category *} + + + + {* Delete category confirmation dialog *} + + + {/block} {block name="javascript-initialization"} @@ -314,14 +462,25 @@ $(function() { {* Set the proper category ID in the delete confirmation dialog *} - $(document).on("click", ".category-delete", function () { - $('#'+'delete-category-id').val($(this).data('id')); + $('a.category-delete').click(function(ev) { + $('#delete_category_id').val($(this).data('id')); }); // Toggle category visibility $(".categoryVisibleToggle").click(function() { $.ajax({ - url : "{url path='admin/catalog/category'}", + url : "{url path='admin/categories/toggle-online'}", + data : { + category_id : $(this).data('id'), + action : 'visibilityToggle' + } + }); + }); + + // Toggle product visibility + $(".productVisibleToggle").click(function() { + $.ajax({ + url : "{url path='admin/products/toggle-online'}", data : { category_id : $(this).data('id'), action : 'visibilityToggle' @@ -338,15 +497,34 @@ $(function() { inputclass : 'input-mini', placement : 'left', success : function(response, newValue) { - // The URL template - var url = "{url path='admin/catalog/category' action='changePosition' category_id='__ID__' position='__POS__'}"; + // The URL template + var url = "{url path='/admin/categories/update-position' category_id='__ID__' position='__POS__'}"; - // Perform subtitutions + // Perform subtitutions url = url.replace('__ID__', $(this).data('id')) - .replace('__POS__', newValue); + .replace('__POS__', newValue); - // Reload the page - location.href = url; + // Reload the page + location.href = url; + } + }); + + $('.productPositionChange').editable({ + type : 'text', + title : '{intl l="Enter new product position"}', + mode : 'popup', + inputclass : 'input-mini', + placement : 'left', + success : function(response, newValue) { + // The URL template + var url = "{url path='/admin/products/update-position' product_id='__ID__' position='__POS__'}"; + + // Perform subtitutions + url = url.replace('__ID__', $(this).data('id')) + .replace('__POS__', newValue); + + // Reload the page + location.href = url; } }); diff --git a/templates/admin/default/edit_category.html b/templates/admin/default/category-edit.html similarity index 99% rename from templates/admin/default/edit_category.html rename to templates/admin/default/category-edit.html index 85e6d42bd..31c425157 100755 --- a/templates/admin/default/edit_category.html +++ b/templates/admin/default/category-edit.html @@ -7,9 +7,8 @@ {block name="main-content"}
- + + {include file="includes/categories-breadcrumb.html"}
{loop name="category_edit" type="category" visible="*" id="{$current_category_id}" backend_context="1" lang="$edit_language_id"} diff --git a/templates/admin/default/currencies.html b/templates/admin/default/currencies.html index 29bd582a2..83ca62ba3 100644 --- a/templates/admin/default/currencies.html +++ b/templates/admin/default/currencies.html @@ -122,7 +122,7 @@
{* display parent category name *} - {loop name="category_title" type="category" visible="*" id="{$current_category_id}"} + {loop name="category_title" type="category" visible="*" id=$current_category_id} {intl l="Products in %cat" cat=$TITLE} {/loop} + {elseloop rel="category_title"} {intl l="Top level Products"} {/elseloop} @@ -183,15 +194,34 @@ {ifloop rel="product_list"}
+ {admin_sortable_header + current_order=$product_order + order='id' + reverse_order='id_reverse' + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='ID'}" + } +   + {admin_sortable_header + current_order=$product_order + order='ref' + reverse_order='ref_reverse' + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Reference'}" + } + {admin_sortable_header current_order=$product_order order='alpha' reverse_order='alpha_reverse' - path={url path='/admin/catalog/product' id="{$current_category_id}"} - label={intl l='Product title'} + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Product title'}" } {module_include location='product_list_header'} @@ -201,8 +231,8 @@ current_order=$product_order order='visible' reverse_order='visible_reverse' - path={url path='/admin/catalog/product' id="{$current_category_id}"} - label={intl l='Online'} + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Online'}" }
{$ID} {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - + #TITLE {/loop} - {$TITLE}{$REF}{$TITLE} - + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"} +
+ +
+ {/loop} + + {elseloop rel="can_change"} +
+ +
+ {/elseloop}
{admin_position_block permission="admin.product.edit" - path={url path='admin/catalog/product' category_id="{$ID}"} + path={url path='admin/product' category_id=$ID} url_parameter="product_id" in_place_edit_class="productPositionChange" - position="$POSITION" - id="$ID" + position=$POSITION + id=$ID } - - +
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.edit"} + + {/loop} + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.delete"} + + {/loop} +
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.currencies.change"} - {$NAME} + {$NAME} {/loop} {elseloop rel="can_change"} {$NAME} diff --git a/templates/admin/default/includes/add-category-dialog.html b/templates/admin/default/includes/add-category-dialog.html deleted file mode 100755 index 0e62994f7..000000000 --- a/templates/admin/default/includes/add-category-dialog.html +++ /dev/null @@ -1,71 +0,0 @@ - -{* Adding a new Category *} - - \ No newline at end of file diff --git a/templates/admin/default/includes/category_breadcrumb.html b/templates/admin/default/includes/category_breadcrumb.html deleted file mode 100755 index bf14142b5..000000000 --- a/templates/admin/default/includes/category_breadcrumb.html +++ /dev/null @@ -1,13 +0,0 @@ -{* Breadcrumb for categories browsing and editing *} - -
  • Home
  • -
  • Catalog {ifloop rel="category_path"}
  • - -{loop name="category_path" type="category-path" visible="*" category="{$current_category_id}"} {if $ID == $current_category_id} -
  • {if $action == 'edit'} {intl l='Editing %cat' cat="{$TITLE}"} {else} {$TITLE} {intl l="(edit)"} {/if} -
  • -{else} -
  • {$TITLE}
  • -{/if} {/loop} {/ifloop} {elseloop rel="category_path"} - -{/elseloop} diff --git a/templates/admin/default/includes/delete-category-dialog.html b/templates/admin/default/includes/delete-category-dialog.html deleted file mode 100755 index 91cc8db66..000000000 --- a/templates/admin/default/includes/delete-category-dialog.html +++ /dev/null @@ -1,42 +0,0 @@ - -{* Adding a new Category *} - -