diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php index 019911265..9203dc00d 100755 --- a/core/lib/Thelia/Action/Cart.php +++ b/core/lib/Thelia/Action/Cart.php @@ -143,7 +143,7 @@ class Cart extends BaseAction implements EventSubscriberInterface return array( "action.addArticle" => array("addItem", 128), "action.deleteArticle" => array("deleteItem", 128), - "action.changeArticle" => array("changeItem", 128), + "action.updateArticle" => array("changeItem", 128), ); } diff --git a/core/lib/Thelia/Action/Category.php b/core/lib/Thelia/Action/Category.php index 28ca2fc9e..1b0568cbe 100755 --- a/core/lib/Thelia/Action/Category.php +++ b/core/lib/Thelia/Action/Category.php @@ -248,9 +248,9 @@ class Category extends BaseAction implements EventSubscriberInterface TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128), TheliaEvents::CATEGORY_CHANGE_POSITION => array("changePosition", 128), - "action.changeCategoryPositionU" => array("changePositionUp", 128), - "action.changeCategoryPositionDown" => array("changePositionDown", 128), - "action.changeCategoryPosition" => array("changePosition", 128), + "action.updateCategoryPositionU" => array("changePositionUp", 128), + "action.updateCategoryPositionDown" => array("changePositionDown", 128), + "action.updateCategoryPosition" => array("changePosition", 128), ); } } diff --git a/core/lib/Thelia/Action/Config.php b/core/lib/Thelia/Action/Config.php index c7b016c63..e0a62f69d 100644 --- a/core/lib/Thelia/Action/Config.php +++ b/core/lib/Thelia/Action/Config.php @@ -31,7 +31,7 @@ use Thelia\Model\Config as ConfigModel; use Thelia\Core\Event\TheliaEvents; -use Thelia\Core\Event\ConfigChangeEvent; +use Thelia\Core\Event\ConfigUpdateEvent; use Thelia\Core\Event\ConfigCreateEvent; use Thelia\Core\Event\ConfigDeleteEvent; @@ -65,9 +65,9 @@ class Config extends BaseAction implements EventSubscriberInterface /** * Change a configuration entry value * - * @param ConfigChangeEvent $event + * @param ConfigUpdateEvent $event */ - public function setValue(ConfigChangeEvent $event) + public function setValue(ConfigUpdateEvent $event) { $search = ConfigQuery::create(); @@ -90,9 +90,9 @@ class Config extends BaseAction implements EventSubscriberInterface /** * Change a configuration entry * - * @param ConfigChangeEvent $event + * @param ConfigUpdateEvent $event */ - public function modify(ConfigChangeEvent $event) + public function modify(ConfigUpdateEvent $event) { $search = ConfigQuery::create(); diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php index c0ca41d60..68cc5904a 100644 --- a/core/lib/Thelia/Action/Currency.php +++ b/core/lib/Thelia/Action/Currency.php @@ -31,11 +31,11 @@ use Thelia\Model\Currency as CurrencyModel; use Thelia\Core\Event\TheliaEvents; -use Thelia\Core\Event\CurrencyChangeEvent; +use Thelia\Core\Event\CurrencyUpdateEvent; use Thelia\Core\Event\CurrencyCreateEvent; use Thelia\Core\Event\CurrencyDeleteEvent; -use Thelia\Model\Map\CurrencyTableMap; use Thelia\Model\ConfigQuery; +use Thelia\Core\Event\CurrencyUpdatePositionEvent; class Currency extends BaseAction implements EventSubscriberInterface { @@ -67,9 +67,9 @@ class Currency extends BaseAction implements EventSubscriberInterface /** * Change a currency * - * @param CurrencyChangeEvent $event + * @param CurrencyUpdateEvent $event */ - public function update(CurrencyChangeEvent $event) + public function update(CurrencyUpdateEvent $event) { $search = CurrencyQuery::create(); @@ -93,9 +93,9 @@ class Currency extends BaseAction implements EventSubscriberInterface /** * Set the default currency * - * @param CurrencyChangeEvent $event + * @param CurrencyUpdateEvent $event */ - public function setDefault(CurrencyChangeEvent $event) + public function setDefault(CurrencyUpdateEvent $event) { $search = CurrencyQuery::create(); @@ -158,18 +158,34 @@ class Currency extends BaseAction implements EventSubscriberInterface } } + /** + * Changes position, selecting absolute ou relative change. + * + * @param CategoryChangePositionEvent $event + */ + public function updatePosition(CurrencyUpdatePositionEvent $event) + { + if (null !== $category = CurrencyQuery::create()->findOneById($event->getObjectId())) { + + if ($event->getMode() == BaseChangePositionEvent::POSITION_ABSOLUTE) + return $category->changeAbsolutePosition($event->getPosition()); + else + return $this->exchangePosition($event->getMode()); + } + } + /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( - TheliaEvents::CURRENCY_CREATE => array("create", 128), - TheliaEvents::CURRENCY_UPDATE => array("update", 128), - TheliaEvents::CURRENCY_DELETE => array("delete", 128), - TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128), - TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128), - + TheliaEvents::CURRENCY_CREATE => array("create", 128), + TheliaEvents::CURRENCY_UPDATE => array("update", 128), + TheliaEvents::CURRENCY_DELETE => array("delete", 128), + TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128), + TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128), + TheliaEvents::CURRENCY_UPDATE_POSITION => array("updatePosition", 128) ); } } diff --git a/core/lib/Thelia/Action/Message.php b/core/lib/Thelia/Action/Message.php index f2335bd82..5299efc99 100644 --- a/core/lib/Thelia/Action/Message.php +++ b/core/lib/Thelia/Action/Message.php @@ -31,7 +31,7 @@ use Thelia\Model\Message as MessageModel; use Thelia\Core\Event\TheliaEvents; -use Thelia\Core\Event\MessageChangeEvent; +use Thelia\Core\Event\MessageUpdateEvent; use Thelia\Core\Event\MessageCreateEvent; use Thelia\Core\Event\MessageDeleteEvent; @@ -65,9 +65,9 @@ class Message extends BaseAction implements EventSubscriberInterface /** * Change a message * - * @param MessageChangeEvent $event + * @param MessageUpdateEvent $event */ - public function modify(MessageChangeEvent $event) + public function modify(MessageUpdateEvent $event) { $search = MessageQuery::create(); diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index eda938f2b..58b6e53c2 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -85,6 +85,12 @@ + + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 58645d531..9f56548ed 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -41,7 +41,7 @@ Thelia\Controller\Admin\ConfigController::defaultAction - + Thelia\Controller\Admin\ConfigController::changeValuesAction @@ -49,7 +49,7 @@ Thelia\Controller\Admin\ConfigController::createAction - + Thelia\Controller\Admin\ConfigController::changeAction @@ -71,7 +71,7 @@ Thelia\Controller\Admin\MessageController::createAction - + Thelia\Controller\Admin\MessageController::changeAction @@ -93,7 +93,7 @@ Thelia\Controller\Admin\CurrencyController::createAction - + Thelia\Controller\Admin\CurrencyController::changeAction @@ -113,6 +113,10 @@ Thelia\Controller\Admin\CurrencyController::deleteAction + + Thelia\Controller\Admin\CurrencyController::updatePositionAction + + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 500fe7427..0ab559873 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -40,7 +40,7 @@ cart - + Thelia\Controller\Front\CartController::deleteItem cart diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 949344685..d5a09a709 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -85,10 +85,16 @@ class BaseAdminController extends BaseController /** * Return a general error page * + * @param mixed $message a message string, or an exception instance + * * @return \Symfony\Component\HttpFoundation\Response */ protected function errorPage($message) { + if ($message instanceof \Exception) { + $message = sprintf("Sorry, an error occured: %s", $message->getMessage()); + } + return $this->render('general_error', array( "error_message" => $message) ); @@ -172,20 +178,27 @@ class BaseAdminController extends BaseController } /** - * Get the current edition lang ID, checking if a change was requested in the current request + * Get the current edition lang ID, checking if a change was requested in the current request. */ - protected function getCurrentEditionLangId() { - return $this->getRequest()->get( - 'edit_language_id', - $this->getSession()->getAdminEditionLangId() - ); + protected function getCurrentEditionLang() { + + // Return the new language if a change is required. + if (null !== $edit_language_id = $this->getRequest()->get('edit_language_id', null)) { + + if (null !== $edit_language = LangQuery::create()->findOneById($edit_language_id)) { + return $edit_language; + } + } + + // Otherwise return the lang stored in session. + return $this->getSession()->getAdminEditionLang(); } /** - * A simple helper to get the current edition locale, from the session edition language ID + * A simple helper to get the current edition locale. */ protected function getCurrentEditionLocale() { - return LangQuery::create()->findOneById($this->getCurrentEditionLangId())->getLocale(); + return $this->getCurrentEditionLang()->getLocale(); } /** @@ -217,23 +230,14 @@ class BaseAdminController extends BaseController $session = $this->getSession(); - $edition_language = $this->getCurrentEditionLangId(); - - // Current back-office (not edition) language - $current_lang = LangQuery::create()->findOneById($session->getLangId()); - // Find the current edit language ID - $edition_language = LangQuery::create()->findOneById($this->getCurrentEditionLangId()); + $edition_language = $this->getCurrentEditionLang(); // Prepare common template variables $args = array_merge($args, array( - 'locale' => $session->getLocale(), - 'lang_code' => $session->getLang(), - 'lang_id' => $session->getLangId(), - - 'datetime_format' => $current_lang->getDateTimeFormat(), - 'date_format' => $current_lang->getDateFormat(), - 'time_format' => $current_lang->getTimeFormat(), + 'locale' => $session->getLang()->getLocale(), + 'lang_code' => $session->getLang()->getCode(), + 'lang_id' => $session->getLang()->getId(), 'edit_language_id' => $edition_language->getId(), 'edit_language_locale' => $edition_language->getLocale(), @@ -242,7 +246,7 @@ class BaseAdminController extends BaseController )); // Update the current edition language in session - $this->getSession()->setAdminEditionLangId($edition_language->getId()); + $this->getSession()->setAdminEditionLang($edition_language); // Render the template. try { diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index d6bcc09ab..b84368c2f 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\ConfigDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Tools\URL; -use Thelia\Core\Event\ConfigChangeEvent; +use Thelia\Core\Event\ConfigUpdateEvent; use Thelia\Core\Event\ConfigCreateEvent; use Thelia\Log\Tlog; use Thelia\Form\Exception\FormValidationException; @@ -154,7 +154,7 @@ class ConfigController extends BaseAdminController public function changeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response; // Load the config object $config = ConfigQuery::create() @@ -196,7 +196,7 @@ class ConfigController extends BaseAdminController public function saveChangeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response; $message = false; @@ -214,7 +214,7 @@ class ConfigController extends BaseAdminController // Get the form field values $data = $form->getData(); - $changeEvent = new ConfigChangeEvent($data['id']); + $changeEvent = new ConfigUpdateEvent($data['id']); // Create and dispatch the change event $changeEvent @@ -241,7 +241,7 @@ class ConfigController extends BaseAdminController if ($this->getRequest()->get('save_mode') == 'stay') { $this->redirectToRoute( - "admin.configuration.variables.change", + "admin.configuration.variables.update", array('variable_id' => $variable_id) ); } @@ -284,13 +284,13 @@ class ConfigController extends BaseAdminController public function changeValuesAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response; $variables = $this->getRequest()->get('variable', array()); // Process all changed variables foreach($variables as $id => $value) { - $event = new ConfigChangeEvent($id); + $event = new ConfigUpdateEvent($id); $event->setValue($value); $this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event); diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 71814d05b..caa3d1bed 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\CurrencyDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Tools\URL; -use Thelia\Core\Event\CurrencyChangeEvent; +use Thelia\Core\Event\CurrencyUpdateEvent; use Thelia\Core\Event\CurrencyCreateEvent; use Thelia\Log\Tlog; use Thelia\Form\Exception\FormValidationException; @@ -34,6 +34,7 @@ use Thelia\Core\Security\Exception\AuthorizationException; use Thelia\Model\CurrencyQuery; use Thelia\Form\CurrencyModificationForm; use Thelia\Form\CurrencyCreationForm; +use Thelia\Core\Event\CurrencyUpdatePositionEvent; /** * Manages currencies sent by mail @@ -124,7 +125,7 @@ class CurrencyController extends BaseAdminController } catch (\Exception $ex) { // Any other error - $error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $error_msg = $ex; } if ($error_msg !== false) { @@ -153,7 +154,7 @@ class CurrencyController extends BaseAdminController public function changeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; // Load the currency object $currency = CurrencyQuery::create() @@ -191,7 +192,7 @@ class CurrencyController extends BaseAdminController public function saveChangeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; $error_msg = false; @@ -209,7 +210,7 @@ class CurrencyController extends BaseAdminController // Get the form field values $data = $form->getData(); - $changeEvent = new CurrencyChangeEvent($data['id']); + $changeEvent = new CurrencyUpdateEvent($data['id']); // Create and dispatch the change event $changeEvent @@ -231,7 +232,7 @@ class CurrencyController extends BaseAdminController // just redirect to the edit page again. if ($this->getRequest()->get('save_mode') == 'stay') { $this->redirectToRoute( - "admin.configuration.currencies.change", + "admin.configuration.currencies.update", array('currency_id' => $currency_id) ); } @@ -245,7 +246,7 @@ class CurrencyController extends BaseAdminController } catch (\Exception $ex) { // Any other error - $error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $error_msg = $ex; } if ($error_msg !== false) { @@ -271,9 +272,9 @@ class CurrencyController extends BaseAdminController */ public function setDefaultAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; - $changeEvent = new CurrencyChangeEvent($this->getRequest()->get('currency_id', 0)); + $changeEvent = new CurrencyUpdateEvent($this->getRequest()->get('currency_id', 0)); // Create and dispatch the change event $changeEvent->setIsDefault(true); @@ -283,7 +284,7 @@ class CurrencyController extends BaseAdminController } catch (\Exception $ex) { // Any error - return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage())); + return $this->errorPage($ex); } $this->redirectToRoute('admin.configuration.currencies.default'); @@ -294,19 +295,50 @@ class CurrencyController extends BaseAdminController */ public function updateRatesAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; try { $this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES); } catch (\Exception $ex) { // Any error - return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage())); + return $this->errorPage($ex); } $this->redirectToRoute('admin.configuration.currencies.default'); } + /** + * Update currencyposition + */ + public function updatePositionAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response; + + try { + $id = $this->getRequest()->get('currency_id', 0); + $mode = $this->getRequest()->get('mode', null); + $position = $this->getRequest()->get('position', null); + + $event = new CurrencyUpdatePositionEvent(); + + $event + ->setObjectId($this->getRequest()->get('currency_id', 0)) + ->setPosition($this->getRequest()->get('position', 0)) + ->setMode($mode) + ; + + $this->dispatch(TheliaEvents::CURRENCY_UPDATE_POSITION, $event); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToRoute('admin.configuration.currencies.default'); + } + + /** * Delete a currency object * diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index 5cc3d2734..8b31e6b52 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\MessageDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Tools\URL; -use Thelia\Core\Event\MessageChangeEvent; +use Thelia\Core\Event\MessageUpdateEvent; use Thelia\Core\Event\MessageCreateEvent; use Thelia\Log\Tlog; use Thelia\Form\Exception\FormValidationException; @@ -133,7 +133,7 @@ class MessageController extends BaseAdminController public function changeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.messages.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response; // Load the message object $message = MessageQuery::create() @@ -173,7 +173,7 @@ class MessageController extends BaseAdminController public function saveChangeAction() { // Check current user authorization - if (null !== $response = $this->checkAuth("admin.configuration.messages.change")) return $response; + if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response; $message = false; @@ -191,7 +191,7 @@ class MessageController extends BaseAdminController // Get the form field values $data = $form->getData(); - $changeEvent = new MessageChangeEvent($data['id']); + $changeEvent = new MessageUpdateEvent($data['id']); // Create and dispatch the change event $changeEvent @@ -215,7 +215,7 @@ class MessageController extends BaseAdminController // just redirect to the edit page again. if ($this->getRequest()->get('save_mode') == 'stay') { $this->redirectToRoute( - "admin.configuration.messages.change", + "admin.configuration.messages.update", array('message_id' => $message_id) ); } diff --git a/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php b/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php index 94f131626..3a3dbb18f 100644 --- a/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php @@ -22,64 +22,7 @@ /*************************************************************************************/ namespace Thelia\Core\Event; -use Thelia\Model\Category; -class CategoryChangePositionEvent extends ActionEvent +class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent { - const POSITION_UP = 1; - const POSITION_DOWN = 2; - const POSITION_ABSOLUTE = 3; - - protected $category_id; - protected $mode; - protected $position; - protected $category; - - public function __construct($category_id, $mode, $position = null) - { - $this->category_id = $category_id; - $this->mode = $mode; - $this->position = $position; - } - - public function getMode() - { - return $this->mode; - } - - public function setMode($mode) - { - $this->mode = $mode; - } - - public function getPosition() - { - return $this->position; - } - - public function setPosition($position) - { - $this->position = $position; - } - - public function getCategory() - { - return $this->category; - } - - public function setCategory($category) - { - $this->category = $category; - } - - public function getCategoryId() - { - return $this->category_id; - } - - public function setCategoryId($category_id) - { - $this->category_id = $category_id; - } - -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryChangeEvent.php b/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php similarity index 97% rename from core/lib/Thelia/Core/Event/CategoryChangeEvent.php rename to core/lib/Thelia/Core/Event/CategoryUpdateEvent.php index e8e183b3f..8103864c5 100644 --- a/core/lib/Thelia/Core/Event/CategoryChangeEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php @@ -25,7 +25,7 @@ namespace Thelia\Core\Event; use Thelia\Model\Category; -class CategoryCreateEvent extends ActionEvent +class CategoryUpdateEvent extends ActionEvent { protected $category_id; protected $locale; diff --git a/core/lib/Thelia/Core/Event/ConfigChangeEvent.php b/core/lib/Thelia/Core/Event/ConfigUpdateEvent.php similarity index 98% rename from core/lib/Thelia/Core/Event/ConfigChangeEvent.php rename to core/lib/Thelia/Core/Event/ConfigUpdateEvent.php index e7da059ee..a73613699 100644 --- a/core/lib/Thelia/Core/Event/ConfigChangeEvent.php +++ b/core/lib/Thelia/Core/Event/ConfigUpdateEvent.php @@ -25,7 +25,7 @@ namespace Thelia\Core\Event; use Thelia\Model\Config; -class ConfigChangeEvent extends ConfigCreateEvent +class ConfigUpdateEvent extends ConfigCreateEvent { protected $config_id; diff --git a/core/lib/Thelia/Core/Event/CurrencyChangeEvent.php b/core/lib/Thelia/Core/Event/CurrencyUpdateEvent.php similarity index 97% rename from core/lib/Thelia/Core/Event/CurrencyChangeEvent.php rename to core/lib/Thelia/Core/Event/CurrencyUpdateEvent.php index 1e7677fee..044a93baa 100644 --- a/core/lib/Thelia/Core/Event/CurrencyChangeEvent.php +++ b/core/lib/Thelia/Core/Event/CurrencyUpdateEvent.php @@ -24,7 +24,7 @@ namespace Thelia\Core\Event; use Thelia\Model\Currency; -class CurrencyChangeEvent extends CurrencyCreateEvent +class CurrencyUpdateEvent extends CurrencyCreateEvent { protected $currency_id; protected $is_default; diff --git a/core/lib/Thelia/Core/Event/MessageChangeEvent.php b/core/lib/Thelia/Core/Event/MessageUpdateEvent.php similarity index 98% rename from core/lib/Thelia/Core/Event/MessageChangeEvent.php rename to core/lib/Thelia/Core/Event/MessageUpdateEvent.php index 1d36f1d30..1b3712266 100644 --- a/core/lib/Thelia/Core/Event/MessageChangeEvent.php +++ b/core/lib/Thelia/Core/Event/MessageUpdateEvent.php @@ -25,7 +25,7 @@ namespace Thelia\Core\Event; use Thelia\Model\Message; -class MessageChangeEvent extends MessageCreateEvent +class MessageUpdateEvent extends MessageCreateEvent { protected $message_id; diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 150edb748..c9a97f6d9 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -124,7 +124,7 @@ final class TheliaEvents /** * Change category position */ - const CATEGORY_CHANGE_POSITION = "action.changeCategoryPosition"; + const CATEGORY_CHANGE_POSITION = "action.updateCategoryPosition"; /** * Sent just after a successful insert of a new category in the database. @@ -220,12 +220,12 @@ final class TheliaEvents // -- Currencies management --------------------------------------------- - const CURRENCY_CREATE = "action.createCurrency"; - const CURRENCY_UPDATE = "action.updateCurrency"; - const CURRENCY_DELETE = "action.deleteCurrency"; - const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency"; - const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates"; - + const CURRENCY_CREATE = "action.createCurrency"; + const CURRENCY_UPDATE = "action.updateCurrency"; + const CURRENCY_DELETE = "action.deleteCurrency"; + const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency"; + const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates"; + const CURRENCY_UPDATE_POSITION = "action.updateCurrencyPosition"; const BEFORE_CREATECURRENCY = "action.before_createCurrency"; const AFTER_CREATECURRENCY = "action.after_createCurrency"; @@ -237,4 +237,4 @@ final class TheliaEvents const AFTER_DELETECURRENCY = "action.after_deleteCurrency"; -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php index 5f311ad0e..53c4c45e8 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php +++ b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php @@ -41,55 +41,29 @@ use Thelia\Model\Lang; */ class Session extends BaseSession { - // -- Language ------------------------------------------------------------ - - public function getLocale() - { - return $this->get("locale", "en_US"); - } - - public function setLocale($locale) - { - $this->set("locale", $locale); - - return $this; - } - /** * @return \Thelia\Model\Lang|null */ public function getLang() { - return $this->get("lang"); + return $this->get("thelia.current.lang", Lang::getDefaultLanguage()); } public function setLang(Lang $lang) { - $this->set("lang", $lang); + $this->set("thelia.current.lang", $lang); return $this; } - public function getLangId() + public function getAdminEditionLang() { - return $this->get("lang_id", Lang::getDefaultLanguage()->getId()); + return $this->get('thelia.admin.edition.lang', Lang::getDefaultLanguage()); } - public function setLangId($langId) + public function setAdminEditionLang($langId) { - $this->set("lang_id", $langId); - - return $this; - } - - public function getAdminEditionLangId() - { - return $this->get('admin.edition_language', Lang::getDefaultLanguage()->getId()); - } - - public function setAdminEditionLangId($langId) - { - $this->set('admin.edition_language', $langId); + $this->set('thelia.admin.edition.lang', $langId); return $this; } @@ -98,43 +72,43 @@ class Session extends BaseSession public function setCustomerUser(UserInterface $user) { - $this->set('customer_user', $user); + $this->set('thelia.customer_user', $user); return $this; } public function getCustomerUser() { - return $this->get('customer_user'); + return $this->get('thelia.customer_user'); } public function clearCustomerUser() { - return $this->remove('customer_user'); + return $this->remove('thelia.customer_user'); } // -- Admin user ----------------------------------------------------------- public function setAdminUser(UserInterface $user) { - $this->set('admin_user', $user); + $this->set('thelia.admin_user', $user); return $this; } public function getAdminUser() { - return $this->get('admin_user'); + return $this->get('thelia.admin_user'); } public function clearAdminUser() { - return $this->remove('admin_user'); + return $this->remove('thelia.admin_user'); } // -- Return page ---------------------------------------------------------- public function setReturnToUrl($url) { - $this->set('return_to_url', $url); + $this->set('thelia.return_to_url', $url); return $this; } @@ -144,7 +118,7 @@ class Session extends BaseSession */ public function getReturnToUrl() { - return $this->get('return_to_url', URL::getIndexPage()); + return $this->get('thelia.return_to_url', URL::getIndexPage()); } // -- Cart ------------------------------------------------------------------ @@ -156,7 +130,7 @@ class Session extends BaseSession */ public function getCart() { - $cart_id = $this->get("cart_id"); + $cart_id = $this->get("thelia.cart_id"); $cart = null; if ($cart_id) { $cart = CartQuery::create()->findPk($cart_id); @@ -193,7 +167,7 @@ class Session extends BaseSession */ public function setCart($cart_id) { - $this->set("cart_id", $cart_id); + $this->set("thelia.cart_id", $cart_id); return $this; } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php b/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php index ef51d51b8..18eadce3c 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php @@ -69,7 +69,7 @@ abstract class BaseI18nLoop extends BaseLoop $this->getBackend_context(), $this->getLang(), $search, - $this->request->getSession()->getLocale(), + $this->request->getSession()->getLang()->getLocale(), $columns, $foreignTable, $foreignKey, diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index befb53dc7..fc05b23a7 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -235,31 +235,6 @@ abstract class BaseLoop } } - /** - * Setup ModelCriteria for proper i18n processing - * - * @param ModelCriteria $search the Propel Criteria to configure - * @param array $columns the i18n columns - * @param string $foreignTable the specified table (default to criteria table) - * @param string $foreignKey the foreign key in this table (default to criteria table) - * - * @return mixed the locale - */ - protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false) { - - /* manage translations */ - return ModelCriteriaTools::getI18n( - $this->getBackend_context(), - $this->getLang(), - $search, - $this->request->getSession()->getLocale(), - $columns, - $foreignTable, - $foreignKey, - $forceReturn - ); - } - /** * * this function have to be implement in your own loop class. diff --git a/core/lib/Thelia/Core/Template/Loop/Config.php b/core/lib/Thelia/Core/Template/Loop/Config.php index f8819afef..a1bba2a98 100644 --- a/core/lib/Thelia/Core/Template/Loop/Config.php +++ b/core/lib/Thelia/Core/Template/Loop/Config.php @@ -167,9 +167,6 @@ class Config extends BaseI18nLoop ->set("CREATE_DATE" , $result->getCreatedAt()) ->set("UPDATE_DATE" , $result->getUpdatedAt()) - ->set("VERSION" , $result->getVersion()) - ->set("VERSION_DATE" , $result->getVersionCreatedAt()) - ->set("VERSION_AUTHOR" , $result->getVersionCreatedBy()) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 475481c2b..10c61adcd 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -13,6 +13,8 @@ class Category extends BaseCategory { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + use \Thelia\Model\Tools\PositionManagementTrait; + /** * @return int number of child for the current category */ @@ -46,18 +48,6 @@ class Category extends BaseCategory $this->save(); } - public function getNextPosition($parent) { - - $last = CategoryQuery::create() - ->filterByParent($parent) - ->orderByPosition(Criteria::DESC) - ->limit(1) - ->findOne() - ; - - return $last != null ? $last->getPosition() + 1 : 1; - } - /** * * count all products for current category and sub categories diff --git a/core/lib/Thelia/Model/Currency.php b/core/lib/Thelia/Model/Currency.php index fc1c86b67..20c36782d 100755 --- a/core/lib/Thelia/Model/Currency.php +++ b/core/lib/Thelia/Model/Currency.php @@ -11,6 +11,8 @@ class Currency extends BaseCurrency { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + use \Thelia\Model\Tools\PositionManagementTrait; + /** * {@inheritDoc} */ diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index a527746ce..e6e3c32dd 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -23,38 +23,100 @@ namespace Thelia\Tools; -use Symfony\Component\HttpFoundation\Request; use Thelia\Model\ConfigQuery; use Thelia\Rewriting\RewritingResolver; use Thelia\Rewriting\RewritingRetriever; -class URL +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Thelia\Core\HttpFoundation\Request; +use Symfony\Component\DependencyInjection\ContainerAware; + +class URL extends ContainerAware { + protected $container; + protected $request; + protected $resolver = null; protected $retriever = null; const PATH_TO_FILE = true; const WITH_INDEX_PAGE = false; - public function __construct() + private static $instance = null; + + public function __construct(Request $request) { + $this->request = $request; + $this->retriever = new RewritingRetriever(); $this->resolver = new RewritingResolver(); + + self::instance = $this; } - public static function getIndexPage() - { - return ConfigQuery::read('base_url', '/') . "index_dev.php"; // FIXME ! + /** + * Give this class a singleton behavior + */ + public static getInstance() { + + return self::$instance; } - public static function init() + /** + * Return the base URL, either the base_url defined in Config, or the URL + * of the current language, if 'one_domain_foreach_lang' is enabled. + * + * @return string the base URL, with a trailing '/' + */ + public function getBaseUrl() { - return new URL(); + // Check if we have a specific URL for each lang. + $one_domain_foreach_lang = ConfigQuery::read("one_domain_foreach_lang", false); + + if ($one_domain_foreach_lang == true) { + // If it's the case, get the current lang URL + $base_url = $this->request->getSession()->getLang()->getUrl(); + + $err_msg = 'base_url'; + } + else { + // Get the base URL + $base_url = ConfigQuery::read('base_url', null); + + $err_msg = sprintf('base_url for lang %s', $this->request->getSession()->getCode()); + } + + // Be sure that base-url starts with http, give up if it's not the case. + if (substr($base_url, 0, 4) != 'http') { + throw new \InvalidArgumentException("The 'base_url' configuration parameter shoud contains the URL of your shop, starting with http or https."); + } + + // Normalize the base_url + return rtrim($base_url, '/').'/'; + } + + /** + * @return string the index page, which is basically the base_url in prod environment. + */ + public function getIndexPage() + { + // Get the base URL + $base_url = $this->getBaseUrl(); + + // Check if we're in dev or prod + $env = $this->container->get(‘kernel’)->getEnvironment(); + + // For dev, add the proper page. + if ($env == 'dev') { + $base_url .= "index_dev.php"; + } + + return $base_url; } /** * Returns the Absolute URL for a given path relative to web root. By default, - * the index.php (or index_dev.php) script name is added to the URL, use + * the script name (index_dev.php) is added to the URL in dev_environment, use * $path_only = true to get a path without the index script. * * @param string $path the relative path @@ -63,7 +125,7 @@ class URL * * @return string The generated URL */ - public static function absoluteUrl($path, array $parameters = null, $path_only = self::WITH_INDEX_PAGE) + public function absoluteUrl($path, array $parameters = null, $path_only = self::WITH_INDEX_PAGE) { // Already absolute ? if (substr($path, 0, 4) != 'http') { @@ -72,9 +134,9 @@ class URL * @etienne : can't be done here for it's already done in ::viewUrl / ::adminViewUrl * @franck : should be done, as absoluteUrl() is sometimes called directly (see UrlGenerator::generateUrlFunction()) */ - $root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : self::getIndexPage(); - //$root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : ''; + $root = $path_only == self::PATH_TO_FILE ? $this->getBaseUrl() : $this->getIndexPage(); + // Normalize root path $base = rtrim($root, '/') . '/' . ltrim($path, '/'); } else $base = $path; @@ -90,6 +152,7 @@ class URL $sepChar = strstr($base, '?') === false ? '?' : '&'; if ('' !== $queryString = rtrim($queryString, "&")) $queryString = $sepChar . $queryString; + return $base . $queryString; } @@ -101,11 +164,11 @@ class URL * * @return string The generated URL */ - public static function adminViewUrl($viewName, array $parameters = array()) + public function adminViewUrl($viewName, array $parameters = array()) { - $path = sprintf("%s/admin/%s", self::getIndexPage(), $viewName); // FIXME ! view= should not be required, check routing parameters + $path = sprintf("%s/admin/%s", $this->getIndexPage(), $viewName); - return self::absoluteUrl($path, $parameters); + return $this->absoluteUrl($path, $parameters); } /** @@ -116,11 +179,11 @@ class URL * * @return string The generated URL */ - public static function viewUrl($viewName, array $parameters = array()) + public function viewUrl($viewName, array $parameters = array()) { $path = sprintf("?view=%s", $viewName); - return self::absoluteUrl($path, $parameters); + return $this>absoluteUrl($path, $parameters); } /** @@ -137,7 +200,7 @@ class URL $rewrittenUrl = $this->retriever->loadViewUrl($view, $viewLocale, $viewId); } - return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; + return $rewrittenUrl === null ? $this->viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; } public function retrieveCurrent(Request $request) diff --git a/templates/admin/default/assets/css/admin.less b/templates/admin/default/assets/css/admin.less index 0bc9fc274..4b5369a80 100755 --- a/templates/admin/default/assets/css/admin.less +++ b/templates/admin/default/assets/css/admin.less @@ -74,6 +74,10 @@ h4 { a { color: #e9720f; font-weight: bold; + + &.btn { + font-weight: normal; + } } // Bootstrap Adjustements ------------------------------------------------------ diff --git a/templates/admin/default/currencies.html b/templates/admin/default/currencies.html index a693214d7..6f5dc0c0d 100644 --- a/templates/admin/default/currencies.html +++ b/templates/admin/default/currencies.html @@ -122,7 +122,7 @@ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.currencies.change"} - {$NAME} + {$NAME} {/loop} {elseloop rel="can_change"} {$NAME} @@ -155,7 +155,7 @@
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.currencies.change"} - + {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.currencies.delete"} @@ -203,7 +203,7 @@ {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created currency ID, see controller *} - + {/form_field} {* We do not allow users to create secured currencies from here *} @@ -371,7 +371,7 @@ placement : 'left', success : function(response, newValue) { // The URL template - var url = "{url path='/admin/configuration/currencies/changePosition' currency_id='__ID__' position='__POS__'}"; + var url = "{url path='/admin/configuration/currencies/updatePosition' currency_id='__ID__' position='__POS__'}"; // Perform subtitutions url = url.replace('__ID__', $(this).data('id')) diff --git a/templates/admin/default/general_error.html b/templates/admin/default/general_error.html index dcbcc80ab..06f7b6608 100755 --- a/templates/admin/default/general_error.html +++ b/templates/admin/default/general_error.html @@ -14,7 +14,7 @@ {block name="error-message"}
{$error_message}
{/block} -

{intl l="Go to administration home"}

+

{intl l="Go to administration home"}

diff --git a/templates/admin/default/messages.html b/templates/admin/default/messages.html index 9a41e922e..1f6cb210e 100644 --- a/templates/admin/default/messages.html +++ b/templates/admin/default/messages.html @@ -20,7 +20,7 @@
-
+
@@ -49,7 +49,7 @@
{if ! $SECURED} {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.messages.change"} - {$NAME} + {$NAME} {/loop} {elseloop rel="can_change"} {$NAME} @@ -65,7 +65,7 @@ {if ! $SECURED}
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.messages.change"} - + {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.messages.delete"} @@ -116,7 +116,7 @@ {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created message ID, see controller *} - + {/form_field} {* We do not allow users to create secured messages from here *} diff --git a/templates/admin/default/variables.html b/templates/admin/default/variables.html index 9b61eca59..fe4554124 100644 --- a/templates/admin/default/variables.html +++ b/templates/admin/default/variables.html @@ -20,7 +20,7 @@
- +
@@ -77,7 +77,7 @@
{if ! $SECURED} {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.variables.change"} - {$NAME} + {$NAME} {/loop} {elseloop rel="can_change"} {$NAME} @@ -103,7 +103,7 @@ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.variables.change"} - + {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.configuration.variables.delete"} @@ -144,7 +144,7 @@ {form_field form=$form field='success_url'} {* on success, redirect to the edition page, _ID_ is replaced with the created variable ID, see controller *} - + {/form_field} {* We do not allow users to create hidden or secured variables from here *}