diff --git a/.travis.yml b/.travis.yml index 1ed4aba4a..3ee2064b8 100755 --- a/.travis.yml +++ b/.travis.yml @@ -12,3 +12,4 @@ before_script: - composer install --prefer-dist --dev - sh -c "mysql -u$DB_USER -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS thelia;SET FOREIGN_KEY_CHECKS = 1;'; fi" - php Thelia thelia:install --db_host=localhost --db_username=$DB_USER --db_name=thelia + - php install/faker.php diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php new file mode 100644 index 000000000..32ec24c05 --- /dev/null +++ b/core/lib/Thelia/Action/Address.php @@ -0,0 +1,108 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\Address as AddressModel; + + +/** + * Class Address + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Address extends BaseAction implements EventSubscriberInterface +{ + + public function create(AddressCreateOrUpdateEvent $event) + { + $address = new AddressModel(); + $address->setCustomer($event->getCustomer()); + $this->createOrUpdate($address, $event); + } + + public function update(AddressCreateOrUpdateEvent $event) + { + $addressModel = $event->getAddress(); + + $this->createOrUpdate($addressModel, $event); + } + + + protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) + { + $addressModel->setDispatcher($this->getDispatcher()); + + 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() + ; + + $event->setAddress($addressModel); + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::ADDRESS_CREATE => array("create", 128), + TheliaEvents::ADDRESS_UPDATE => array("update", 128) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Action/Category.php b/core/lib/Thelia/Action/Category.php index 59604bab9..28ca2fc9e 100755 --- a/core/lib/Thelia/Action/Category.php +++ b/core/lib/Thelia/Action/Category.php @@ -53,7 +53,7 @@ class Category extends BaseAction implements EventSubscriberInterface ); } - public function modify(CategoryChangeEvent $event) + public function update(CategoryChangeEvent $event) { } @@ -242,7 +242,7 @@ class Category extends BaseAction implements EventSubscriberInterface { return array( TheliaEvents::CATEGORY_CREATE => array("create", 128), - TheliaEvents::CATEGORY_MODIFY => array("modify", 128), + TheliaEvents::CATEGORY_UPDATE => array("update", 128), TheliaEvents::CATEGORY_DELETE => array("delete", 128), TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128), diff --git a/core/lib/Thelia/Action/Config.php b/core/lib/Thelia/Action/Config.php index fa683f1d4..c7b016c63 100644 --- a/core/lib/Thelia/Action/Config.php +++ b/core/lib/Thelia/Action/Config.php @@ -148,7 +148,7 @@ class Config extends BaseAction implements EventSubscriberInterface return array( TheliaEvents::CONFIG_CREATE => array("create", 128), TheliaEvents::CONFIG_SETVALUE => array("setValue", 128), - TheliaEvents::CONFIG_MODIFY => array("modify", 128), + TheliaEvents::CONFIG_UPDATE => array("modify", 128), TheliaEvents::CONFIG_DELETE => array("delete", 128), ); } diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index e9ec5483f..08db66dda 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -24,25 +24,12 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Thelia\Core\Event\ActionEvent; -use Thelia\Core\Event\Coupon\CouponCreateEvent; -use Thelia\Core\Event\Coupon\CouponDisableEvent; -use Thelia\Core\Event\Coupon\CouponEnableEvent; +use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; -use Thelia\Model\Category as CategoryModel; -use Thelia\Form\CategoryCreationForm; -use Thelia\Core\Event\CategoryEvent; -use Thelia\Model\CouponQuery; -use Thelia\Tools\Redirect; -use Thelia\Model\CategoryQuery; -use Thelia\Model\AdminLog; -use Thelia\Form\CategoryDeletionForm; -use Thelia\Action\Exception\FormValidationException; - +use Thelia\Model\Coupon as CouponModel; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Propel; use Thelia\Model\Map\CategoryTableMap; -use Propel\Runtime\Exception\PropelException; /** * Created by JetBrains PhpStorm. @@ -58,102 +45,57 @@ use Propel\Runtime\Exception\PropelException; class Coupon extends BaseAction implements EventSubscriberInterface { /** - * Create a Coupon if a Coupon creation attempt is found + * Occurring when a Coupon is about to be created * - * @param CouponCreateEvent $event Coupon creation Event + * @param CouponCreateOrUpdateEvent $event Event creation or update Event */ - public function create(CouponCreateEvent $event) + public function create(CouponCreateOrUpdateEvent $event) { - $this->checkAuth("ADMIN", "admin.coupon.create"); + $coupon = new CouponModel(); - $this->dispatch( - TheliaEvents::BEFORE_CREATE_COUPON, - $event - ); - - $couponModel = CouponQuery::create(); - $event->getCreatedCoupon()->save(); - - $this->dispatch( - TheliaEvents::AFTER_CREATE_COUPON, - $event - ); + $this->createOrUpdate($coupon, $event); } /** - * Edit a Coupon if a Coupon edition attempt is found + * Occurring when a Coupon is about to be updated * - * @param CouponEditEvent $event Coupon edition Event + * @param CouponCreateOrUpdateEvent $event Event creation or update Event */ - public function edit(CouponEditEvent $event) + public function update(CouponCreateOrUpdateEvent $event) { - $this->checkAuth("ADMIN", "admin.coupon.edit"); + $coupon = $event->getCoupon(); - $this->dispatch( - TheliaEvents::BEFORE_EDIT_COUPON, - $event - ); - - $couponToUpdate = CouponQuery::create()->findPk($event->getId()); - - if ($couponToUpdate !== null) { - $event->getCreatedCoupon()->save(); - } - - $this->dispatch( - TheliaEvents::AFTER_EDIT_COUPON, - $event - ); + $this->createOrUpdate($coupon, $event); } /** - * Disable a Coupon if a Coupon disable attempt is found + * Call the Model and delegate the create or delete action + * Feed the Event with the updated model * - * @param CouponDisableEvent $event Coupon disable Event + * @param CouponModel $coupon Model to save + * @param CouponCreateOrUpdateEvent $event Event containing data */ - public function disable(CouponDisableEvent $event) + protected function createOrUpdate(CouponModel $coupon, CouponCreateOrUpdateEvent $event) { - $this->checkAuth("ADMIN", "admin.coupon.disable"); + $coupon->setDispatcher($this->getDispatcher()); - $couponToUpdate = CouponQuery::create()->findPk($event->getId()); + $coupon->createOrUpdate( + $event->getCode(), + $event->getTitle(), + $event->getAmount(), + $event->getEffect(), + $event->getShortDescription(), + $event->getDescription(), + $event->isEnabled(), + $event->getExpirationDate(), + $event->isAvailableOnSpecialOffers(), + $event->isCumulative(), + $event->getMaxUsage(), + $event->getRules(), + $event->getLang() + ); - if ($couponToUpdate !== null) { - $couponToUpdate->setIsEnabled(0); - $event->getDispatcher()->dispatch( - TheliaEvents::BEFORE_DISABLE_COUPON, $event - ); - - $couponToUpdate->save(); - - $event->getDispatcher()->dispatch( - TheliaEvents::AFTER_DISABLE_COUPON, $event - ); - } - } - - /** - * Enable a Coupon if a Coupon enable attempt is found - * - * @param CouponEnableEvent $event Coupon enable Event - */ - public function enable(CouponEnableEvent $event) - { - $this->checkAuth("ADMIN", "admin.coupon.enable"); - - $couponToUpdate = CouponQuery::create()->findPk($event->getId()); - - if ($couponToUpdate !== null) { - $couponToUpdate->setIsEnabled(1); - $event->getDispatcher()->dispatch( - TheliaEvents::BEFORE_ENABLE_COUPON, $event - ); - - $couponToUpdate->save(); - - $event->getDispatcher()->dispatch( - TheliaEvents::AFTER_ENABLE_COUPON, $event - ); - } + $event->setCoupon($coupon); } /** @@ -179,14 +121,8 @@ class Coupon extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( -// "action.createCategory" => array("create", 128), -// "action.modifyCategory" => array("modify", 128), -// "action.deleteCategory" => array("delete", 128), -// -// "action.toggleCategoryVisibility" => array("toggleVisibility", 128), -// "action.changeCategoryPositionUp" => array("changePositionUp", 128), -// "action.changeCategoryPositionDown" => array("changePositionDown", 128), -// "action.changeCategoryPosition" => array("changePosition", 128), + TheliaEvents::COUPON_CREATE => array("create", 128), + TheliaEvents::COUPON_UPDATE => array("update", 128), ); } } diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php index 4e3bb45d4..c0ca41d60 100644 --- a/core/lib/Thelia/Action/Currency.php +++ b/core/lib/Thelia/Action/Currency.php @@ -34,6 +34,8 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\CurrencyChangeEvent; use Thelia\Core\Event\CurrencyCreateEvent; use Thelia\Core\Event\CurrencyDeleteEvent; +use Thelia\Model\Map\CurrencyTableMap; +use Thelia\Model\ConfigQuery; class Currency extends BaseAction implements EventSubscriberInterface { @@ -53,11 +55,12 @@ class Currency extends BaseAction implements EventSubscriberInterface ->setName($event->getCurrencyName()) ->setSymbol($event->getSymbol()) ->setRate($event->getRate()) - ->setCode($event->getCode()) + ->setCode(strtoupper($event->getCode())) ->save() ; + $event->setCurrency($currency); } @@ -66,7 +69,7 @@ class Currency extends BaseAction implements EventSubscriberInterface * * @param CurrencyChangeEvent $event */ - public function modify(CurrencyChangeEvent $event) + public function update(CurrencyChangeEvent $event) { $search = CurrencyQuery::create(); @@ -79,7 +82,7 @@ class Currency extends BaseAction implements EventSubscriberInterface ->setName($event->getCurrencyName()) ->setSymbol($event->getSymbol()) ->setRate($event->getRate()) - ->setCode($event->getCode()) + ->setCode(strtoupper($event->getCode())) ->save(); @@ -87,6 +90,32 @@ class Currency extends BaseAction implements EventSubscriberInterface } } + /** + * Set the default currency + * + * @param CurrencyChangeEvent $event + */ + public function setDefault(CurrencyChangeEvent $event) + { + $search = CurrencyQuery::create(); + + if (null !== $currency = CurrencyQuery::create()->findOneById($event->getCurrencyId())) { + + if ($currency->getByDefault() != $event->getIsDefault()) { + + // Reset default status + CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false)); + + $currency + ->setByDefault($event->getIsDefault()) + ->save() + ; + } + + $event->setCurrency($currency); + } + } + /** * Delete a currencyuration entry * @@ -106,15 +135,41 @@ class Currency extends BaseAction implements EventSubscriberInterface } } + public function updateRates() { + + $rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'); + + $rate_data = file_get_contents($rates_url); + + if ($rate_data && $sxe = new \SimpleXMLElement($rate_data)) { + + foreach ($sxe->Cube[0]->Cube[0]->Cube as $last) + { + $code = strtoupper($last["currency"]); + $rate = floatval($last['rate']); + + if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) { + $currency->setRate($rate)->save(); + } + } + } + else { + throw new \RuntimeException(sprintf("Failed to get currency rates data from URL %s", $url)); + } + } + /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( - TheliaEvents::CURRENCY_CREATE => array("create", 128), - TheliaEvents::CURRENCY_MODIFY => array("modify", 128), - TheliaEvents::CURRENCY_DELETE => array("delete", 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), + ); } } diff --git a/core/lib/Thelia/Action/Message.php b/core/lib/Thelia/Action/Message.php index dd50a5652..f2335bd82 100644 --- a/core/lib/Thelia/Action/Message.php +++ b/core/lib/Thelia/Action/Message.php @@ -118,7 +118,7 @@ class Message extends BaseAction implements EventSubscriberInterface { return array( TheliaEvents::MESSAGE_CREATE => array("create", 128), - TheliaEvents::MESSAGE_MODIFY => array("modify", 128), + TheliaEvents::MESSAGE_UPDATE => array("modify", 128), TheliaEvents::MESSAGE_DELETE => array("delete", 128), ); } diff --git a/core/lib/Thelia/Action/PageNotFound.php b/core/lib/Thelia/Action/PageNotFound.php new file mode 100755 index 000000000..c6f547fc4 --- /dev/null +++ b/core/lib/Thelia/Action/PageNotFound.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\KernelEvents; +use Thelia\Model\ConfigQuery; + +/** + * + * Class PageNotFound + * @package Thelia\Action + * @author Etienne Roudeix + */ +class PageNotFound extends BaseAction implements EventSubscriberInterface +{ + public function display404(GetResponseForExceptionEvent $event) + { + if(is_a($event->getException(), 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException')) { + + $parser = $this->container->get("thelia.parser"); + + // Define the template thant shoud be used + $parser->setTemplate(ConfigQuery::getActiveTemplate()); + + //$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView()); + + $response = new Response($parser->render(ConfigQuery::getPageNotFoundView()), 404); + + $event->setResponse($response); + } + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + KernelEvents::EXCEPTION => array("display404", 128), + ); + } +} diff --git a/core/lib/Thelia/Command/Install.php b/core/lib/Thelia/Command/Install.php index 2e10d77ee..03b7fda48 100755 --- a/core/lib/Thelia/Command/Install.php +++ b/core/lib/Thelia/Command/Install.php @@ -28,6 +28,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Thelia\Command\ContainerAwareCommand; +use Thelia\Install\Database; /** * try to install a new instance of Thelia @@ -97,14 +98,16 @@ class Install extends ContainerAwareCommand $connectionInfo = $this->getConnectionInfo($input, $output); } - $this->createDatabase($connection, $connectionInfo["dbName"]); + $database = new Database($connection); + + $database->createDatabase($connectionInfo["dbName"]); $output->writeln(array( "", "Creating Thelia database, please wait", "" )); - $this->insertSql($connection, $connectionInfo["dbName"]); + $database->insertSql($connectionInfo["dbName"]); $output->writeln(array( "", @@ -203,65 +206,6 @@ class Install extends ContainerAwareCommand } - /** - * Insert all sql needed in database - * - * @param \PDO $connection - * @param $dbName - */ - protected function insertSql(\PDO $connection, $dbName) - { - $connection->query(sprintf("use %s", $dbName)); - $sql = array(); - $sql = array_merge( - $sql, - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) - ); - - for ($i = 0; $i < count($sql); $i ++) { - $connection->query($sql[$i]); - } - } - - /** - * Separate each sql instruction in an array - * - * @param $sql - * @return array - */ - protected function prepareSql($sql) - { - $sql = str_replace(";',", "-CODE-", $sql); - $query = array(); - - $tab = explode(";", $sql); - - for ($i=0; $iquery( - sprintf( - "CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8", - $dbName - ) - ); - } - /** * test database access * diff --git a/core/lib/Thelia/Command/ReloadDatabaseCommand.php b/core/lib/Thelia/Command/ReloadDatabaseCommand.php new file mode 100644 index 000000000..d25add644 --- /dev/null +++ b/core/lib/Thelia/Command/ReloadDatabaseCommand.php @@ -0,0 +1,70 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; +use Propel\Runtime\Propel; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Thelia\Install\Database; + + +/** + * Class ReloadDatabasesCommand + * @package Thelia\Command + * @author Manuel Raynaud + */ +class ReloadDatabaseCommand extends BaseModuleGenerate +{ + public function configure() + { + $this + ->setName("thelia:dev:reloadDB") + ->setDescription("erase current database and create new one") +/* ->addOption( + "load-fixtures", + null, + InputOption::VALUE_NONE, + "load fixtures in databases" + )*/ + ; + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $connection = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME); + $connection = $connection->getWrappedConnection(); + + $database = new Database($connection); + $output->writeln(array( + '', + 'starting reloaded database, please wait' + )); + $database->insertSql(); + $output->writeln(array( + '', + 'Database reloaded with success', + '' + )); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index bcc162e24..7eea2e005 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -47,6 +47,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 4edb39ab1..ce78f5010 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -70,6 +70,7 @@ + @@ -169,17 +170,23 @@ - + - + + + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index 9c61c55a8..5200aefc1 100755 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -56,6 +56,17 @@ + + + install.xml + + %kernel.cache_dir% + %kernel.debug% + + + + + front.xml diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index d0e44e580..0058ee5f8 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -130,6 +130,14 @@ Thelia\Controller\Admin\CurrencyController::saveChangeAction + + Thelia\Controller\Admin\CurrencyController::setDefaultAction + + + + Thelia\Controller\Admin\CurrencyController::updateRatesAction + + Thelia\Controller\Admin\CurrencyController::deleteAction diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 9329b22ad..500fe7427 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -9,6 +9,7 @@ index + Thelia\Controller\Front\CustomerController::createAction connexion @@ -25,7 +26,15 @@ Thelia\Controller\Front\CustomerController::logoutAction + + + + Thelia\Controller\Front\CustomerAddressController::createAction + + + + Thelia\Controller\Front\CartController::addItem cart @@ -40,4 +49,8 @@ Thelia\Controller\Front\CartController::changeItem cart + + + Thelia\Controller\Front\UrlRewritingController::check + diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml new file mode 100644 index 000000000..d53763948 --- /dev/null +++ b/core/lib/Thelia/Config/Resources/routing/install.xml @@ -0,0 +1,15 @@ + + + + + + Thelia\Controller\Install\InstallController::index + + + + Thelia\Controller\Install\InstallController::checkPermission + + + diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 8160033fe..949344685 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -150,12 +150,33 @@ class BaseAdminController extends BaseController return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST); } + /** + * Return the route path defined for the givent route ID + * + * @param string $routeId a route ID, as defines in Config/Resources/routing/admin.xml + * + * @see \Thelia\Controller\BaseController::getRouteFromRouter() + */ + protected function getRoute($routeId) { + return $this->getRouteFromRouter('router.admin', $routeId); + } + + /** + * Redirect to à route ID related URL + * + * @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml + * @param unknown $urlParameters the URL parametrs, as a var/value pair array + */ + public function redirectToRoute($routeId, $urlParameters = array()) { + $this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters)); + } + /** * Get the current edition lang ID, checking if a change was requested in the current request */ protected function getCurrentEditionLangId() { return $this->getRequest()->get( - 'edition_language', + 'edit_language_id', $this->getSession()->getAdminEditionLangId() ); } @@ -196,29 +217,32 @@ class BaseAdminController extends BaseController $session = $this->getSession(); - // Find the current edit language ID $edition_language = $this->getCurrentEditionLangId(); // Current back-office (not edition) language - $current_lang = LangQuery::create()->findOneById($session->getLangId()); + $current_lang = LangQuery::create()->findOneById($session->getLangId()); + + // Find the current edit language ID + $edition_language = LangQuery::create()->findOneById($this->getCurrentEditionLangId()); // Prepare common template variables $args = array_merge($args, array( - 'locale' => $session->getLocale(), - 'lang_code' => $session->getLang(), - 'lang_id' => $session->getLangId(), + '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(), + 'datetime_format' => $current_lang->getDateTimeFormat(), + 'date_format' => $current_lang->getDateFormat(), + 'time_format' => $current_lang->getTimeFormat(), - 'edition_language' => $edition_language, + 'edit_language_id' => $edition_language->getId(), + 'edit_language_locale' => $edition_language->getLocale(), - 'current_url' => htmlspecialchars($this->getRequest()->getUri()) + 'current_url' => htmlspecialchars($this->getRequest()->getUri()) )); // Update the current edition language in session - $this->getSession()->setAdminEditionLangId($edition_language); + $this->getSession()->setAdminEditionLangId($edition_language->getId()); // Render the template. try { diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 582358812..0b1970e84 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -188,7 +188,7 @@ class CategoryController extends BaseAdminController // Find the current order $category_order = $this->getRequest()->get( - 'category_order', + 'order', $this->getSession()->get('admin.category_order', 'manual') ); diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index 8f761ed7e..d6bcc09ab 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -42,6 +42,25 @@ use Thelia\Form\ConfigCreationForm; */ class ConfigController extends BaseAdminController { + /** + * Render the currencies list, ensuring the sort order is set. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + protected function renderList() { + + // Find the current order + $order = $this->getRequest()->get( + 'order', + $this->getSession()->get('admin.variables_order', 'name') + ); + + // Store the current sort order in session + $this->getSession()->set('admin.variables_order', $order); + + return $this->render('variables', array('order' => $order)); + } + /** * The default action is displaying the variables list. * @@ -51,7 +70,7 @@ class ConfigController extends BaseAdminController if (null !== $response = $this->checkAuth("admin.configuration.variables.view")) return $response; - return $this->render('variables'); + return $this->renderList(); } /** @@ -124,7 +143,7 @@ class ConfigController extends BaseAdminController } // At this point, the form has error, and should be redisplayed. - return $this->render('variables'); + return $this->renderList(); } /** @@ -210,7 +229,7 @@ class ConfigController extends BaseAdminController ->setPostscriptum($data['postscriptum']) ; - $this->dispatch(TheliaEvents::CONFIG_MODIFY, $changeEvent); + $this->dispatch(TheliaEvents::CONFIG_UPDATE, $changeEvent); // Log config modification $changedObject = $changeEvent->getConfig(); @@ -220,10 +239,11 @@ class ConfigController extends BaseAdminController // 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->redirect(URL::absoluteUrl( - "admin/configuration/variables/change", + + $this->redirectToRoute( + "admin.configuration.variables.change", array('variable_id' => $variable_id) - )); + ); } // Redirect to the success URL @@ -276,7 +296,7 @@ class ConfigController extends BaseAdminController $this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event); } - $this->redirect(URL::adminViewUrl('variables')); + $this->redirectToRoute('admin.configuration.variables.default'); } /** @@ -294,6 +314,6 @@ class ConfigController extends BaseAdminController $this->dispatch(TheliaEvents::CONFIG_DELETE, $event); - $this->redirect(URL::adminViewUrl('variables')); + $this->redirectToRoute('admin.configuration.variables.default'); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 69cc60117..71814d05b 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -83,7 +83,7 @@ class CurrencyController extends BaseAdminController // Check current user authorization if (null !== $response = $this->checkAuth("admin.configuration.currencies.create")) return $response; - $currency = false; + $error_msg = false; // Create the Creation Form $creationForm = new CurrencyCreationForm($this->getRequest()); @@ -101,7 +101,9 @@ class CurrencyController extends BaseAdminController ->setCurrencyName($data['name']) ->setLocale($data["locale"]) ->setSymbol($data['symbol']) - ; + ->setCode($data['code']) + ->setRate($data['rate']) + ; $this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent); @@ -118,24 +120,24 @@ class CurrencyController extends BaseAdminController } catch (FormValidationException $ex) { // Form cannot be validated - $currency = sprintf("Please check your input: %s", $ex->getCurrency()); + $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); } catch (\Exception $ex) { // Any other error - $currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency()); + $error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage()); } - if ($currency !== false) { + if ($error_msg !== false) { // An error has been detected: log it - Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $currency, $ex->getCurrency())); + Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $error_msg, $ex->getMessage())); // Mark the form as errored - $creationForm->setErrorCurrency($currency); + $creationForm->setErrorMessage($error_msg); // Pass it to the parser, along with the error currency $this->getParserContext() ->addForm($creationForm) - ->setGeneralError($currency) + ->setGeneralError($error_msg) ; } @@ -167,7 +169,7 @@ class CurrencyController extends BaseAdminController 'locale' => $currency->getLocale(), 'code' => $currency->getCode(), 'symbol' => $currency->getSymbol(), - 'rate' => $currency->getSubject() + 'rate' => $currency->getRate() ); // Setup the object form @@ -191,7 +193,7 @@ class CurrencyController extends BaseAdminController // Check current user authorization if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response; - $currency = false; + $error_msg = false; // Create the form from the request $changeForm = new CurrencyModificationForm($this->getRequest()); @@ -218,7 +220,7 @@ class CurrencyController extends BaseAdminController ->setRate($data['rate']) ; - $this->dispatch(TheliaEvents::CURRENCY_MODIFY, $changeEvent); + $this->dispatch(TheliaEvents::CURRENCY_UPDATE, $changeEvent); // Log currency modification $changedObject = $changeEvent->getCurrency(); @@ -228,10 +230,10 @@ class CurrencyController extends BaseAdminController // 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->redirect(URL::absoluteUrl( - "admin/configuration/currencies/change", + $this->redirectToRoute( + "admin.configuration.currencies.change", array('currency_id' => $currency_id) - )); + ); } // Redirect to the success URL @@ -239,24 +241,24 @@ class CurrencyController extends BaseAdminController } catch (FormValidationException $ex) { // Invalid data entered - $currency = sprintf("Please check your input: %s", $ex->getCurrency()); + $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); } catch (\Exception $ex) { // Any other error - $currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency()); + $error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage()); } - if ($currency !== false) { + if ($error_msg !== false) { // Log error currency - Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $currency, $ex->getCurrency())); + Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage())); // Mark the form as errored - $changeForm->setErrorCurrency($currency); + $changeForm->setErrorMessage($error_msg); // Pas the form and the error to the parser $this->getParserContext() ->addForm($changeForm) - ->setGeneralError($currency) + ->setGeneralError($error_msg) ; } @@ -264,6 +266,47 @@ class CurrencyController extends BaseAdminController return $this->render('currency-edit', array('currency_id' => $currency_id)); } + /** + * Sets the default currency + */ + public function setDefaultAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response; + + $changeEvent = new CurrencyChangeEvent($this->getRequest()->get('currency_id', 0)); + + // Create and dispatch the change event + $changeEvent->setIsDefault(true); + + try { + $this->dispatch(TheliaEvents::CURRENCY_SET_DEFAULT, $changeEvent); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage())); + } + + $this->redirectToRoute('admin.configuration.currencies.default'); + } + + /** + * Update currencies rates + */ + public function updateRatesAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) 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())); + } + + $this->redirectToRoute('admin.configuration.currencies.default'); + } + /** * Delete a currency object * @@ -279,6 +322,6 @@ class CurrencyController extends BaseAdminController $this->dispatch(TheliaEvents::CURRENCY_DELETE, $event); - $this->redirect(URL::adminViewUrl('currencies')); + $this->redirectToRoute('admin.configuration.currencies.default'); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index 5a53fd28a..5cc3d2734 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -204,7 +204,7 @@ class MessageController extends BaseAdminController ->setTextMessage($data['text_message']) ; - $this->dispatch(TheliaEvents::MESSAGE_MODIFY, $changeEvent); + $this->dispatch(TheliaEvents::MESSAGE_UPDATE, $changeEvent); // Log message modification $changedObject = $changeEvent->getMessage(); @@ -214,10 +214,10 @@ class MessageController extends BaseAdminController // 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->redirect(URL::absoluteUrl( - "admin/configuration/messages/change", + $this->redirectToRoute( + "admin.configuration.messages.change", array('message_id' => $message_id) - )); + ); } // Redirect to the success URL diff --git a/core/lib/Thelia/Controller/Admin/SessionController.php b/core/lib/Thelia/Controller/Admin/SessionController.php index 552fea8eb..a377df208 100755 --- a/core/lib/Thelia/Controller/Admin/SessionController.php +++ b/core/lib/Thelia/Controller/Admin/SessionController.php @@ -46,7 +46,7 @@ class SessionController extends BaseAdminController $this->getSecurityContext()->clearAdminUser(); // Go back to login page. - return Redirect::exec(URL::absoluteUrl('/admin/login')); // FIXME - should be a parameter + $this->redirectToRoute('admin.login'); } public function checkLoginAction() diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index c7c9f6f14..853776214 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -31,11 +31,12 @@ use Thelia\Tools\Redirect; use Thelia\Core\Template\ParserContext; use Thelia\Core\Event\ActionEvent; use Symfony\Component\EventDispatcher\EventDispatcher; -use Thelia\Core\Factory\ActionEventFactory; use Thelia\Form\BaseForm; use Thelia\Form\Exception\FormValidationException; use Symfony\Component\EventDispatcher\Event; use Thelia\Core\Event\DefaultActionEvent; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * @@ -177,9 +178,9 @@ class BaseController extends ContainerAware * * @param string $url */ - public function redirect($url) + public function redirect($url, $status = 302) { - Redirect::exec($url); + Redirect::exec($url, $status); } /** @@ -200,4 +201,32 @@ class BaseController extends ContainerAware if (null !== $url) $this->redirect($url); } -} + + /** + * Get a route path from the route id. + * + * @param $routerName + * @param $routeId + * + * @return mixed + * @throws InvalidArgumentException + */ + protected function getRouteFromRouter($routerName, $routeId) { + $route = $this->container->get($routerName)->getRouteCollection()->get($routeId); + + if ($route == null) { + throw new InvalidArgumentException(sprintf("Route ID '%s' does not exists.", $routeId)); + } + + return $route->getPath(); + } + + /** + * Return a 404 error + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + */ + protected function pageNotFound() + { + throw new NotFoundHttpException(); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index c466ab0c6..b6d4a6f93 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -26,4 +26,24 @@ use Thelia\Controller\BaseController; class BaseFrontController extends BaseController { + /** + * Return the route path defined for the givent route ID + * + * @param string $routeId a route ID, as defines in Config/Resources/routing/front.xml + * + * @see \Thelia\Controller\BaseController::getRouteFromRouter() + */ + protected function getRoute($routeId) { + return $this->getRouteFromRouter('router.front', $routeId); + } + + /** + * Redirect to à route ID related URL + * + * @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml + * @param unknown $urlParameters the URL parametrs, as a var/value pair array + */ + public function redirectToRoute($routeId, $urlParameters = array()) { + $this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters)); + } } diff --git a/core/lib/Thelia/Controller/Front/CartController.php b/core/lib/Thelia/Controller/Front/CartController.php index 8f2cdd036..c3d928a15 100755 --- a/core/lib/Thelia/Controller/Front/CartController.php +++ b/core/lib/Thelia/Controller/Front/CartController.php @@ -74,7 +74,7 @@ class CartController extends BaseFrontController $cartEvent->setQuantity($this->getRequest()->get("quantity")); try { - $this->getDispatcher()->dispatch(TheliaEvents::CART_CHANGEITEM, $cartEvent); + $this->getDispatcher()->dispatch(TheliaEvents::CART_UPDATEITEM, $cartEvent); $this->redirectSuccess(); } catch(PropelException $e) { diff --git a/core/lib/Thelia/Controller/Front/CustomerAddressController.php b/core/lib/Thelia/Controller/Front/CustomerAddressController.php new file mode 100644 index 000000000..4f44ce1d1 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/CustomerAddressController.php @@ -0,0 +1,96 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Front; +use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Form\AddressForm; +use Thelia\Form\Exception\FormValidationException; +use Thelia\Model\Customer; +use Thelia\Tools\URL; + + +/** + * Class CustomerAddressController + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ +class CustomerAddressController extends BaseFrontController +{ + + public function createAction() + { + if ($this->getSecurityContext()->hasCustomerUser() === false) { + $this->redirect(URL::getIndexPage()); + } + + $addressCreate = new AddressForm($this->getRequest()); + + try { + $customer = $this->getSecurityContext()->getCustomerUser(); + + $form = $this->validateForm($addressCreate, "post"); + $event = $this->createAddressEvent($form->getData(), $customer); + + $this->dispatch(TheliaEvents::ADDRESS_CREATE, $event); + $this->redirectSuccess($addressCreate); + + }catch (FormValidationException $e) { + $message = sprintf("Please check your input: %s", $e->getMessage()); + } + catch (\Exception $e) { + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); + } + + if ($message !== false) { + \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message)); + + $addressCreate->setErrorMessage($message); + + $this->getParserContext() + ->addForm($addressCreate) + ->setGeneralError($message) + ; + } + } + + protected function createAddressEvent($data, Customer $customer) + { + return new AddressCreateOrUpdateEvent( + $data["label"], + $data["title"], + $data["firstname"], + $data["lastname"], + $data["address1"], + $data["address2"], + $data["address3"], + $data["zipcode"], + $data["city"], + $data["country"], + $data["cellpone"], + $data["phone"], + $data["company"], + $customer + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php index 005fd6d01..88e15396e 100755 --- a/core/lib/Thelia/Controller/Front/CustomerController.php +++ b/core/lib/Thelia/Controller/Front/CustomerController.php @@ -40,6 +40,11 @@ use Thelia\Tools\URL; use Thelia\Log\Tlog; use Thelia\Core\Security\Exception\WrongPasswordException; +/** + * Class CustomerController + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ class CustomerController extends BaseFrontController { /** @@ -66,10 +71,10 @@ class CustomerController extends BaseFrontController $this->redirectSuccess($customerCreation); } catch (FormValidationException $e) { - $message = sprintf("Please check your input: %s", $ex->getMessage()); + $message = sprintf("Please check your input: %s", $e->getMessage()); } catch (\Exception $e) { - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); } if ($message !== false) { @@ -114,14 +119,14 @@ class CustomerController extends BaseFrontController } catch (FormValidationException $e) { - $message = sprintf("Please check your input: %s", $ex->getMessage()); + $message = sprintf("Please check your input: %s", $e->getMessage()); } catch (\Exception $e) { - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); } if ($message !== false) { - Tlog::getInstance()->error(sprintf("Error during customer modification process : %s. Exception was %s", $message, $e->getMessage())); + Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message)); $customerModification->setErrorMessage($message); @@ -146,11 +151,10 @@ class CustomerController extends BaseFrontController $message = false; $request = $this->getRequest(); + $customerLoginForm = new CustomerLogin($request); try { - $customerLoginForm = new CustomerLogin($request); - $form = $this->validateForm($customerLoginForm, "post"); $authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm); @@ -163,7 +167,7 @@ class CustomerController extends BaseFrontController } catch (FormValidationException $e) { - $message = sprintf("Please check your input: %s", $ex->getMessage()); + $message = sprintf("Please check your input: %s", $e->getMessage()); } catch(UsernameNotFoundException $e) { $message = "This customer email was not found."; @@ -175,7 +179,7 @@ class CustomerController extends BaseFrontController $message = "Sorry, we failed to authentify you. Please try again."; } catch (\Exception $e) { - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = sprintf("Sorry, an error occured: %s", $e->getMessage()); } if ($message !== false) { @@ -190,8 +194,6 @@ class CustomerController extends BaseFrontController /** * Perform customer logout. - * - * @param Customer $customer */ public function logoutAction() { @@ -203,6 +205,11 @@ class CustomerController extends BaseFrontController $this->redirect(URL::getIndexPage()); } + /** + * Dispatch event for customer login action + * + * @param Customer $customer + */ protected function processLogin(Customer $customer) { $this->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer)); diff --git a/core/lib/Thelia/Controller/Front/DefaultController.php b/core/lib/Thelia/Controller/Front/DefaultController.php index 235e1bb64..d9c5a681a 100755 --- a/core/lib/Thelia/Controller/Front/DefaultController.php +++ b/core/lib/Thelia/Controller/Front/DefaultController.php @@ -23,6 +23,9 @@ namespace Thelia\Controller\Front; use Symfony\Component\HttpFoundation\Request; +use Thelia\Model\ConfigQuery; +use Thelia\Tools\Redirect; +use Thelia\Tools\URL; /** * @@ -43,6 +46,16 @@ class DefaultController extends BaseFrontController */ public function noAction(Request $request) { + if(ConfigQuery::isRewritingEnable()) { + + /* Does the query GET parameters match a rewritten URL ? */ + $rewrittenUrl = URL::init()->retrieveCurrent($request); + if($rewrittenUrl->rewrittenUrl !== null) { + /* 301 redirection to rewritten URL */ + $this->redirect($rewrittenUrl->rewrittenUrl, 301); + } + } + if (! $view = $request->query->get('view')) { $view = "index"; if ($request->request->has('view')) { diff --git a/core/lib/Thelia/Controller/Front/UrlRewritingController.php b/core/lib/Thelia/Controller/Front/UrlRewritingController.php new file mode 100755 index 000000000..df2479969 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/UrlRewritingController.php @@ -0,0 +1,81 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Controller\Front; + +use Thelia\Core\HttpFoundation\Request; +use Thelia\Exception\UrlRewritingException; +use Thelia\Model\ConfigQuery; +use Thelia\Tools\URL; + +class UrlRewritingController extends BaseFrontController +{ + public function check(Request $request, $rewritten_url) + { + if(ConfigQuery::isRewritingEnable()) { + try { + $rewrittenUrlData = URL::init()->resolve($rewritten_url); + } catch(UrlRewritingException $e) { + switch($e->getCode()) { + case UrlRewritingException::URL_NOT_FOUND : + return $this->pageNotFound(); + break; + default: + throw $e; + } + } + + /* is the URL redirected ? */ + + if(null !== $rewrittenUrlData->redirectedToUrl) { + $this->redirect($rewrittenUrlData->redirectedToUrl, 301); + } + + /* define GET arguments in request */ + + if(null !== $rewrittenUrlData->view) { + $request->query->set('view', $rewrittenUrlData->view); + if(null !== $rewrittenUrlData->viewId) { + $request->query->set($rewrittenUrlData->view . '_id', $rewrittenUrlData->viewId); + } + } + if(null !== $rewrittenUrlData->locale) { + $request->query->set('locale', $rewrittenUrlData->locale); + } + + foreach($rewrittenUrlData->otherParameters as $parameter => $value) { + $request->query->set($parameter, $value); + } + } + + if (! $view = $request->query->get('view')) { + $view = "index"; + if ($request->request->has('view')) { + $view = $request->request->get('view'); + } + } + + $request->attributes->set('_view', $view); + + } + +} diff --git a/core/lib/Thelia/Controller/Install/BaseInstallController.php b/core/lib/Thelia/Controller/Install/BaseInstallController.php new file mode 100644 index 000000000..a5cbbd506 --- /dev/null +++ b/core/lib/Thelia/Controller/Install/BaseInstallController.php @@ -0,0 +1,60 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Install; +use Symfony\Component\HttpFoundation\Response; +use Thelia\Controller\BaseController; + + +/** + * Class BaseInstallController + * @package Thelia\Controller\Install + * @author Manuel Raynaud + */ +class BaseInstallController extends BaseController +{ + /** + * @return a ParserInterface instance parser + */ + protected function getParser() + { + $parser = $this->container->get("thelia.parser"); + + // Define the template thant shoud be used + $parser->setTemplate("install"); + + return $parser; + } + + public function render($templateName, $args = array()) + { + return new Response($this->renderRaw($templateName, $args)); + } + + public function renderRaw($templateName, $args = array()) + { + $data = $this->getParser()->render($templateName, $args); + + return $data; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php new file mode 100644 index 000000000..209eea82b --- /dev/null +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -0,0 +1,69 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Install; +use Thelia\Install\BaseInstall; +use Thelia\Install\CheckPermission; + +/** + * Class InstallController + * @package Thelia\Controller\Install + * @author Manuel Raynaud + */ +class InstallController extends BaseInstallController { + + public function index() + { + $this->verifyStep(1); + + $this->getSession()->set("step", 1); + + $this->render("index.html"); + } + + public function checkPermission() + { + $this->verifyStep(2); + + $permission = new CheckPermission(); + } + + protected function verifyStep($step) + { + $session = $this->getSession(); + + if ($session->has("step")) { + $sessionStep = $session->get("step"); + } else { + return true; + } + + switch($step) { + case "1" : + if ($sessionStep > 1) { + $this->redirect("/install/step/2"); + } + break; + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php index 2d7110ee5..505d7a3fa 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php @@ -84,7 +84,7 @@ class RegisterRouterPass implements CompilerPassInterface $container->setDefinition("router.".$moduleCode, $definition); - $chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), -1)); + $chainRouter->addMethodCall("add", array(new Reference("router.".$moduleCode), 1)); } } } diff --git a/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php new file mode 100644 index 000000000..1eee2acc8 --- /dev/null +++ b/core/lib/Thelia/Core/Event/AddressCreateOrUpdateEvent.php @@ -0,0 +1,267 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; +use Symfony\Component\EventDispatcher\Event; +use Thelia\Model\Address; +use Thelia\Model\Customer; + + +/** + * Class AddressCreateOrUpdateEvent + * @package Thelia\Core\Event + * @author Manuel Raynaud + */ +class AddressCreateOrUpdateEvent extends Event +{ + /** + * @var string address label + */ + protected $label; + + /** + * @var int title id + */ + protected $title; + + /** + * @var string|null company name + */ + protected $company; + + /** + * @var string first name + */ + protected $firstname; + + /** + * @var string last name + */ + protected $lastname; + + /** + * @var string address + */ + protected $address1; + + /** + * @var string address line 2 + */ + protected $address2; + + /** + * @var string address line 3 + */ + protected $address3; + + /** + * @var string zipcode + */ + protected $zipcode; + + /** + * @var string city + */ + protected $city; + + /** + * @var int country id + */ + protected $country; + + /** + * @var string cell phone + */ + protected $cellphone; + + /** + * @var string phone + */ + protected $phone; + + /** + * @var \Thelia\Model\Customer + */ + protected $customer; + + /** + * @var \Thelia\Model\Address + */ + protected $address; + + function __construct($label, $title, $firstname, $lastname, $address1, $address2, $address3, $zipcode, $city, $country, $cellphone, $phone, $company) + { + $this->address1 = $address1; + $this->address2 = $address2; + $this->address3 = $address3; + $this->cellphone = $cellphone; + $this->city = $city; + $this->company = $company; + $this->country = $country; + $this->firstname = $firstname; + $this->label = $label; + $this->lastname = $lastname; + $this->phone = $phone; + $this->title = $title; + $this->zipcode = $zipcode; + } + + /** + * @return string + */ + public function getAddress1() + { + return $this->address1; + } + + /** + * @return string + */ + public function getAddress2() + { + return $this->address2; + } + + /** + * @return string + */ + public function getAddress3() + { + return $this->address3; + } + + /** + * @return string + */ + public function getCellphone() + { + return $this->cellphone; + } + + /** + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * @return null|string + */ + public function getCompany() + { + return $this->company; + } + + /** + * @return int + */ + public function getCountry() + { + return $this->country; + } + + /** + * @return string + */ + public function getFirstname() + { + return $this->firstname; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @return string + */ + public function getLastname() + { + return $this->lastname; + } + + /** + * @return string + */ + public function getPhone() + { + return $this->phone; + } + + /** + * @return int + */ + public function getTitle() + { + return $this->title; + } + + /** + * @return string + */ + public function getZipcode() + { + return $this->zipcode; + } + + /** + * @param \Thelia\Model\Customer $customer + */ + public function setCustomer(Customer $customer) + { + $this->customer = $customer; + } + + /** + * @return \Thelia\Model\Customer + */ + public function getCustomer() + { + return $this->customer; + } + + /** + * @param \Thelia\Model\Address $address + */ + public function setAddress(Address $address) + { + $this->address = $address; + $this->setCustomer($address->getCustomer()); + } + + /** + * @return \Thelia\Model\Address + */ + public function getAddress() + { + return $this->address; + } + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php similarity index 94% rename from core/lib/Thelia/Core/Event/Coupon/CouponEvent.php rename to core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php index c7b8802cc..90c5559d4 100644 --- a/core/lib/Thelia/Core/Event/Coupon/CouponEvent.php +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateOrUpdateEvent.php @@ -38,11 +38,8 @@ use Thelia\Model\Coupon; * @author Guillaume MOREL * */ -class CouponEvent extends ActionEvent +class CouponCreateOrUpdateEvent extends ActionEvent { - /** @var int Coupon Id */ - protected $id = null; - /** @var CouponRuleCollection Array of CouponRuleInterface */ protected $rules = null; @@ -85,6 +82,9 @@ class CouponEvent extends ActionEvent /** @var string Coupon effect */ protected $effect; + /** @var string Language code ISO (ex: fr_FR) */ + protected $lang = null; + /** * Constructor * @@ -101,7 +101,7 @@ class CouponEvent extends ActionEvent * @param boolean $isRemovingPostage Is removing Postage * @param int $maxUsage Coupon quantity * @param CouponRuleCollection $rules CouponRuleInterface to add - * @param int $id Coupon id + * @param string $lang Coupon Language code ISO (ex: fr_FR) */ function __construct( $code, @@ -111,19 +111,18 @@ class CouponEvent extends ActionEvent $shortDescription, $description, $isEnabled, - $expirationDate, + \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $rules, - $id = null + $lang ) { $this->amount = $amount; $this->code = $code; $this->description = $description; $this->expirationDate = $expirationDate; - $this->id = $id; $this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers; $this->isCumulative = $isCumulative; $this->isEnabled = $isEnabled; @@ -133,16 +132,7 @@ class CouponEvent extends ActionEvent $this->shortDescription = $shortDescription; $this->title = $title; $this->effect = $effect; - } - - /** - * Return Coupon Id - * - * @return int - */ - public function getId() - { - return $this->id; + $this->lang = $lang; } /** @@ -242,7 +232,7 @@ class CouponEvent extends ActionEvent * * @return boolean */ - public function getIsAvailableOnSpecialOffers() + public function isAvailableOnSpecialOffers() { return $this->isAvailableOnSpecialOffers; } @@ -278,7 +268,15 @@ class CouponEvent extends ActionEvent return $this->effect; } - + /** + * Coupon Language code ISO (ex: fr_FR) + * + * @return string + */ + public function getLang() + { + return $this->lang; + } /** * @param \Thelia\Model\Coupon $coupon diff --git a/core/lib/Thelia/Core/Event/CurrencyChangeEvent.php b/core/lib/Thelia/Core/Event/CurrencyChangeEvent.php index f94d71b88..1e7677fee 100644 --- a/core/lib/Thelia/Core/Event/CurrencyChangeEvent.php +++ b/core/lib/Thelia/Core/Event/CurrencyChangeEvent.php @@ -27,6 +27,7 @@ use Thelia\Model\Currency; class CurrencyChangeEvent extends CurrencyCreateEvent { protected $currency_id; + protected $is_default; public function __construct($currency_id) { @@ -44,4 +45,16 @@ class CurrencyChangeEvent extends CurrencyCreateEvent return $this; } -} \ No newline at end of file + + public function getIsDefault() + { + return $this->is_default; + } + + public function setIsDefault($is_default) + { + $this->is_default = $is_default; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/CurrencyCreateEvent.php b/core/lib/Thelia/Core/Event/CurrencyCreateEvent.php index fba23a09b..d9d345ddd 100644 --- a/core/lib/Thelia/Core/Event/CurrencyCreateEvent.php +++ b/core/lib/Thelia/Core/Event/CurrencyCreateEvent.php @@ -65,6 +65,8 @@ class CurrencyCreateEvent extends CurrencyEvent public function setSymbol($symbol) { $this->symbol = $symbol; + + return $this; } public function getCode() diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 21a8199bc..c8dde8758 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -64,7 +64,7 @@ final class TheliaEvents /** * sent on customer account update */ - const CUSTOMER_UPDATEACCOUNT = "action.modifyCustomer"; + const CUSTOMER_UPDATEACCOUNT = "action.updateCustomer"; /** * Sent before the logout of the administrator. @@ -88,12 +88,21 @@ final class TheliaEvents /** * Sent once the customer change form has been successfully validated, and before customer update in the database. */ - const BEFORE_CHANGECUSTOMER = "action.before_changecustomer"; + const BEFORE_CHANGECUSTOMER = "action.before_updateCustomer"; /** * Sent just after a successful update of a customer in the database. */ - const AFTER_CHANGECUSTOMER = "action.after_changecustomer"; + const AFTER_CHANGECUSTOMER = "action.after_updateCustomer"; + /** + * sent for address creation + */ + const ADDRESS_CREATE = "action.createAddress"; + + /** + * sent for address creation + */ + const ADDRESS_UPDATE = "action.updateAddress"; /** * Sent once the category creation form has been successfully validated, and before category insertion in the database. @@ -104,7 +113,7 @@ final class TheliaEvents * Create, change or delete a category */ const CATEGORY_CREATE = "action.createCategory"; - const CATEGORY_MODIFY = "action.modifyCategory"; + const CATEGORY_UPDATE = "action.updateCategory"; const CATEGORY_DELETE = "action.deleteCategory"; /** @@ -134,12 +143,12 @@ final class TheliaEvents /** * Sent just before a successful change of a category in the database. */ - const BEFORE_CHANGECATEGORY = "action.before_changecategory"; + const BEFORE_UPDATECATEGORY = "action.before_updateCategory"; /** * Sent just after a successful change of a category in the database. */ - const AFTER_CHANGECATEGORY = "action.after_changecategory"; + const AFTER_UPDATECATEGORY = "action.after_updateCategory"; /** * sent when a new existing cat id duplicated. This append when current customer is different from current cart @@ -154,7 +163,7 @@ final class TheliaEvents /** * sent when a cart item is modify */ - const AFTER_CARTCHANGEITEM = "cart.modifyItem"; + const AFTER_CARTUPDATEITEM = "cart.updateItem"; /** * sent for addArticle action @@ -164,7 +173,7 @@ final class TheliaEvents /** * sent on modify article action */ - const CART_CHANGEITEM = "action.changeArticle"; + const CART_UPDATEITEM = "action.updateArticle"; const CART_DELETEITEM = "action.deleteArticle"; @@ -254,14 +263,14 @@ final class TheliaEvents const CONFIG_CREATE = "action.createConfig"; const CONFIG_SETVALUE = "action.setConfigValue"; - const CONFIG_MODIFY = "action.changeConfig"; + const CONFIG_UPDATE = "action.updateConfig"; const CONFIG_DELETE = "action.deleteConfig"; const BEFORE_CREATECONFIG = "action.before_createConfig"; const AFTER_CREATECONFIG = "action.after_createConfig"; - const BEFORE_CHANGECONFIG = "action.before_changeConfig"; - const AFTER_CHANGECONFIG = "action.after_changeConfig"; + const BEFORE_UPDATECONFIG = "action.before_updateConfig"; + const AFTER_UPDATECONFIG = "action.after_updateConfig"; const BEFORE_DELETECONFIG = "action.before_deleteConfig"; const AFTER_DELETECONFIG = "action.after_deleteConfig"; @@ -269,30 +278,35 @@ final class TheliaEvents // -- Messages management --------------------------------------------- const MESSAGE_CREATE = "action.createMessage"; - const MESSAGE_MODIFY = "action.changeMessage"; + const MESSAGE_UPDATE = "action.updateMessage"; const MESSAGE_DELETE = "action.deleteMessage"; const BEFORE_CREATEMESSAGE = "action.before_createMessage"; const AFTER_CREATEMESSAGE = "action.after_createMessage"; - const BEFORE_CHANGEMESSAGE = "action.before_changeMessage"; - const AFTER_CHANGEMESSAGE = "action.after_changeMessage"; + const BEFORE_UPDATEMESSAGE = "action.before_updateMessage"; + const AFTER_UPDATEMESSAGE = "action.after_updateMessage"; const BEFORE_DELETEMESSAGE = "action.before_deleteMessage"; const AFTER_DELETEMESSAGE = "action.after_deleteMessage"; // -- Currencies management --------------------------------------------- - const CURRENCY_CREATE = "action.createCurrency"; - const CURRENCY_MODIFY = "action.changeCurrency"; - const CURRENCY_DELETE = "action.deleteCurrency"; + 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 BEFORE_CREATECURRENCY = "action.before_createCurrency"; const AFTER_CREATECURRENCY = "action.after_createCurrency"; - const BEFORE_CHANGECURRENCY = "action.before_changeCurrency"; - const AFTER_CHANGECURRENCY = "action.after_changeCurrency"; + const BEFORE_UPDATECURRENCY = "action.before_updateCurrency"; + const AFTER_UPDATECURRENCY = "action.after_updateCurrency"; const BEFORE_DELETECURRENCY = "action.before_deleteCurrency"; const AFTER_DELETECURRENCY = "action.after_deleteCurrency"; + + } diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index 22c31a2e4..d55826d56 100755 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -86,7 +86,7 @@ class ViewListener implements EventSubscriberInterface } catch (AuthenticationException $ex) { // Redirect to the login template - $event->setResponse(Redirect::exec(URL::viewUrl($ex->getLoginTemplate()))); + Redirect::exec(URL::viewUrl($ex->getLoginTemplate())); } } diff --git a/core/lib/Thelia/Core/Security/SecurityContext.php b/core/lib/Thelia/Core/Security/SecurityContext.php index 6ddb47f00..3f60db08f 100755 --- a/core/lib/Thelia/Core/Security/SecurityContext.php +++ b/core/lib/Thelia/Core/Security/SecurityContext.php @@ -67,7 +67,7 @@ class SecurityContext */ public function hasAdminUser() { - return $this->getSession()->getAdminUser() != null; + return $this->getSession()->getAdminUser() !== null; } /** @@ -87,7 +87,7 @@ class SecurityContext */ public function hasCustomerUser() { - return $this->getSession()->getCustomerUser() != null; + return $this->getSession()->getCustomerUser() !== null; } /** diff --git a/core/lib/Thelia/Core/Template/Loop/Address.php b/core/lib/Thelia/Core/Template/Loop/Address.php index eb837eb4b..43bbbaefb 100755 --- a/core/lib/Thelia/Core/Template/Loop/Address.php +++ b/core/lib/Thelia/Core/Template/Loop/Address.php @@ -114,22 +114,24 @@ class Address extends BaseLoop foreach ($addresses as $address) { $loopResultRow = new LoopResultRow(); - $loopResultRow->set("ID", $address->getId()); - $loopResultRow->set("NAME", $address->getName()); - $loopResultRow->set("CUSTOMER", $address->getCustomerId()); - $loopResultRow->set("TITLE", $address->getTitleId()); - $loopResultRow->set("COMPANY", $address->getCompany()); - $loopResultRow->set("FIRSTNAME", $address->getFirstname()); - $loopResultRow->set("LASTNAME", $address->getLastname()); - $loopResultRow->set("ADDRESS1", $address->getAddress1()); - $loopResultRow->set("ADDRESS2", $address->getAddress2()); - $loopResultRow->set("ADDRESS3", $address->getAddress3()); - $loopResultRow->set("ZIPCODE", $address->getZipcode()); - $loopResultRow->set("CITY", $address->getCity()); - $loopResultRow->set("COUNTRY", $address->getCountryId()); - $loopResultRow->set("PHONE", $address->getPhone()); - $loopResultRow->set("CELLPHONE", $address->getCellphone()); - $loopResultRow->set("DEFAULT", $address->getIsDefault()); + $loopResultRow + ->set("ID", $address->getId()) + ->set("NAME", $address->getName()) + ->set("CUSTOMER", $address->getCustomerId()) + ->set("TITLE", $address->getTitleId()) + ->set("COMPANY", $address->getCompany()) + ->set("FIRSTNAME", $address->getFirstname()) + ->set("LASTNAME", $address->getLastname()) + ->set("ADDRESS1", $address->getAddress1()) + ->set("ADDRESS2", $address->getAddress2()) + ->set("ADDRESS3", $address->getAddress3()) + ->set("ZIPCODE", $address->getZipcode()) + ->set("CITY", $address->getCity()) + ->set("COUNTRY", $address->getCountryId()) + ->set("PHONE", $address->getPhone()) + ->set("CELLPHONE", $address->getCellphone()) + ->set("DEFAULT", $address->getIsDefault()) + ; $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php index 63f1e9cfb..afcd0410e 100755 --- a/core/lib/Thelia/Core/Template/Loop/CategoryTree.php +++ b/core/lib/Thelia/Core/Template/Loop/CategoryTree.php @@ -107,8 +107,6 @@ class CategoryTree extends BaseI18nLoop $visible = $this->getVisible(); $exclude = $this->getExclude(); - //echo "exclude=".print_r($exclude); - $loopResult = new LoopResult(); $this->buildCategoryTree($id, $visible, 0, $depth, $exclude, $loopResult); diff --git a/core/lib/Thelia/Core/Template/Loop/Config.php b/core/lib/Thelia/Core/Template/Loop/Config.php index 5cc1b2b44..f8819afef 100644 --- a/core/lib/Thelia/Core/Template/Loop/Config.php +++ b/core/lib/Thelia/Core/Template/Loop/Config.php @@ -34,6 +34,8 @@ use Thelia\Model\LangQuery; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Model\ConfigQuery; use Thelia\Type\BooleanOrBothType; +use Thelia\Type\TypeCollection; +use Thelia\Type\EnumListType; /** * Config loop, to access configuration variables @@ -59,7 +61,21 @@ class Config extends BaseI18nLoop Argument::createIntListTypeArgument('exclude'), Argument::createAnyTypeArgument('variable'), Argument::createBooleanOrBothTypeArgument('hidden'), - Argument::createBooleanOrBothTypeArgument('secured') + Argument::createBooleanOrBothTypeArgument('secured'), + new Argument( + 'order', + new TypeCollection( + new EnumListType( + array( + 'id', 'id_reverse', + 'name', 'name_reverse', + 'title', 'title_reverse', + 'value', 'value_reverse', + ) + ) + ), + 'name' + ) ); } @@ -94,7 +110,39 @@ class Config extends BaseI18nLoop if (! is_null($secured) && $secured != BooleanOrBothType::ANY) $search->filterBySecured($secured ? 1 : 0); - $search->orderByName(Criteria::ASC); + $orders = $this->getOrder(); + + foreach($orders as $order) { + switch ($order) { + case 'id': + $search->orderById(Criteria::ASC); + break; + case 'id_reverse': + $search->orderById(Criteria::DESC); + break; + + case 'name': + $search->orderByName(Criteria::ASC); + break; + case 'name_reverse': + $search->orderByName(Criteria::DESC); + break; + + case 'title': + $search->addAscendingOrderByColumn('i18n_TITLE'); + break; + case 'title_reverse': + $search->addDescendingOrderByColumn('i18n_TITLE'); + break; + + case 'value': + $search->orderByValue(Criteria::ASC); + break; + case 'value_reverse': + $search->orderByValue(Criteria::DESC); + break; + } + } $results = $this->search($search, $pagination); @@ -116,9 +164,13 @@ class Config extends BaseI18nLoop ->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("HIDDEN" , $result->getHidden()) ->set("SECURED" , $result->getSecured()) - ->set("CREATE_DATE" , $result->getCreatedAt()) - ->set("UPDATE_DATE" , $result->getUpdatedAt()) - ; + + ->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/Core/Template/Loop/Currency.php b/core/lib/Thelia/Core/Template/Loop/Currency.php index 2fb296070..6db6c6223 100755 --- a/core/lib/Thelia/Core/Template/Loop/Currency.php +++ b/core/lib/Thelia/Core/Template/Loop/Currency.php @@ -66,8 +66,9 @@ class Currency extends BaseI18nLoop 'code', 'code_reverse', 'symbol', 'symbol_reverse', 'rate', 'rate_reverse', + 'is_default', 'is_default_reverse', 'manual', 'manual_reverse') - ) + ) ), 'manual' ) @@ -143,6 +144,13 @@ class Currency extends BaseI18nLoop $search->orderByRate(Criteria::DESC); break; + case 'is_default': + $search->orderByByDefault(Criteria::ASC); + break; + case 'is_default_reverse': + $search->orderByByDefault(Criteria::DESC); + break; + case 'manual': $search->orderByPosition(Criteria::ASC); break; @@ -169,7 +177,11 @@ class Currency extends BaseI18nLoop ->set("SYMBOL" , $currency->getSymbol()) ->set("RATE" , $currency->getRate()) ->set("POSITION" , $currency->getPosition()) - ->set("IS_DEFAULT" , $currency->getByDefault()); + ->set("IS_DEFAULT" , $currency->getByDefault()) + + ->set("CREATE_DATE" , $currency->getCreatedAt()) + ->set("UPDATE_DATE" , $currency->getUpdatedAt()) + ; $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index a35ff90b3..17ecd3212 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -519,6 +519,12 @@ class Product extends BaseI18nLoop ->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo')) ->set("IS_NEW", $product->getVirtualColumn('main_product_is_new')) ->set("POSITION", $product->getPosition()) + + ->set("CREATE_DATE", $category->getCreatedAt()) + ->set("UPDATE_DATE", $category->getUpdatedAt()) + ->set("VERSION", $category->getVersion()) + ->set("VERSION_DATE", $category->getVersionCreatedAt()) + ->set("VERSION_AUTHOR", $category->getVersionCreatedBy()) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php new file mode 100644 index 000000000..aab63177a --- /dev/null +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -0,0 +1,144 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Smarty\Plugins; + +use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; +use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Tools\URL; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Security\SecurityContext; + +/** + * This class implements variour admin template utilities + * + * @author Franck Allimant + */ +class AdminUtilities extends AbstractSmartyPlugin +{ + private $securityContext; + + public function __construct(SecurityContext $securityContext) + { + $this->securityContext = $securityContext; + } + + public function generatePositionChangeBlock($params, &$smarty) { + // The required permissions + $permission = $this->getParam($params, 'permission'); + + // The base position change path + $path = $this->getParam($params, 'path'); + + // The URL parameter the object ID is assigned + $url_parameter = $this->getParam($params, 'url_parameter'); + + // The current object position + $position = $this->getParam($params, 'position'); + + // The object ID + $id = $this->getParam($params, 'id'); + + // The in place dition class + $in_place_edit_class = $this->getParam($params, 'in_place_edit_class'); + + /* + + {$POSITION} + + */ + + if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($permission))) { + return sprintf( + '%s', + URL::absoluteUrl("$path/positionUp", array($url_parameter => $id)), + $in_place_edit_class, + $id, + $position, + URL::absoluteUrl("$path/positionDown", array($url_parameter => $id)) + ); + } + else { + return $position; + } + } + + + /** + * Generates the link of a sortable column header + * + * @param array $params + * @param unknown $smarty + * @return string no text is returned. + */ + public function generateSortableColumnHeader($params, &$smarty) + { + // The current order of the table + $current_order = $this->getParam($params, 'current_order'); + + // The column ascending order + $order = $this->getParam($params, 'order'); + + // The column descending order label + $reverse_order = $this->getParam($params, 'reverse_order'); + + // The order change path + $path = $this->getParam($params, 'path'); + + // The column label + $label = $this->getParam($params, 'label'); + + if ($current_order == $order) { + $icon = 'up'; + $order_change = $reverse_order; + } + else if ($current_order == $reverse_order) { + $icon = 'down'; + $order_change = $order; + } + else { + $order_change = $order; + } + + if (! empty($icon)) + $output = sprintf(' ', $icon); + else + $output = ''; + + return sprintf('%s%s', $output, URL::absoluteUrl($path, array('order' => $order_change)), $label); + } + + + /** + * Define the various smarty plugins handled by this class + * + * @return an array of smarty plugin descriptors + */ + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor('function', 'admin_sortable_header', $this, 'generateSortableColumnHeader'), + new SmartyPluginDescriptor('function', 'admin_position_block' , $this, 'generatePositionChangeBlock'), + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index 33e699c43..635c03b8c 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -147,7 +147,7 @@ class UrlGenerator extends AbstractSmartyPlugin { return array( "current" => "getCurrentUrl", - "return_to" => "getReturnToUrl", + "return_to" => "getReturnToUrl", "index" => "getIndexUrl", ); } @@ -169,7 +169,9 @@ class UrlGenerator extends AbstractSmartyPlugin protected function getCurrentUrl() { - return URL::retrieveCurrent($this->request); + $retriever = URL::init()->retrieveCurrent($this->request); + + return $retriever->rewrittenUrl === null ? $retriever->url : $retriever->rewrittenUrl ; } protected function getReturnToUrl() diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 12014e817..89c7eb457 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -36,6 +36,7 @@ class SmartyParser extends Smarty implements ParserInterface /** * @param Request $request * @param EventDispatcherInterface $dispatcher + * @param ParserContext $parserContext * @param bool $template * @param string $env * @param bool $debug diff --git a/core/lib/Thelia/Exception/UrlRewritingException.php b/core/lib/Thelia/Exception/UrlRewritingException.php new file mode 100755 index 000000000..0df566a6b --- /dev/null +++ b/core/lib/Thelia/Exception/UrlRewritingException.php @@ -0,0 +1,42 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Exception; + +use Thelia\Log\Tlog; + +class UrlRewritingException extends \Exception +{ + const UNKNOWN_EXCEPTION = 0; + + const URL_NOT_FOUND = 404; + + const RESOLVER_NULL_SEARCH = 800; + + public function __construct($message, $code = null, $previous = null) { + if($code === null) { + $code = self::UNKNOWN_EXCEPTION; + } + parent::__construct($message, $code, $previous); + } +} diff --git a/core/lib/Thelia/Form/AddressForm.php b/core/lib/Thelia/Form/AddressForm.php new file mode 100644 index 000000000..b98577927 --- /dev/null +++ b/core/lib/Thelia/Form/AddressForm.php @@ -0,0 +1,132 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form; +use Symfony\Component\Validator\Constraints\NotBlank; + + +/** + * Class AddressForm + * @package Thelia\Form + * @author Manuel Raynaud + */ +class AddressForm extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add("label", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "address name" + )) + ->add("title", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "title" + )) + ->add("firstname", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "first name" + )) + ->add("lastname", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "last name" + )) + ->add("address1", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "address" + )) + ->add("address2", "text", array( + "label" => "address (line 2)" + )) + ->add("address3", "text", array( + "label" => "address (line 3)" + )) + ->add("zipcode", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "zipcode" + )) + ->add("city", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "city" + )) + ->add("country", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "country" + )) + ->add("phone", "text", array( + "label" => "phone" + )) + ->add("cellphone", "text", array( + "label" => "cellphone" + )) + ->add("company", "text", array( + "label" => "company" + )) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return "thelia_address_creation"; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 8f1d3f59e..4761bb28f 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -136,6 +136,15 @@ class CouponCreationForm extends BaseForm new NotBlank() ) ) + ) + ->add( + 'locale', + 'hidden', + array( + 'constraints' => array( + new NotBlank() + ) + ) ); } diff --git a/core/lib/Thelia/Form/CurrencyCreationForm.php b/core/lib/Thelia/Form/CurrencyCreationForm.php index 11a496582..a4d858ed6 100644 --- a/core/lib/Thelia/Form/CurrencyCreationForm.php +++ b/core/lib/Thelia/Form/CurrencyCreationForm.php @@ -31,20 +31,20 @@ class CurrencyCreationForm extends BaseForm { protected function buildForm($change_mode = false) { - $name_constraints = array(new Constraints\NotBlank()); + $code_constraints = array(new Constraints\NotBlank()); if (!$change_mode) { - $name_constraints[] = new Constraints\Callback(array( - "methods" => array(array($this, "checkDuplicateName")) + $code_constraints[] = new Constraints\Callback(array( + "methods" => array(array($this, "checkDuplicateCode")) )); } $this->formBuilder - ->add("name" , "text" , array("constraints" => array($name_constraints))) - ->add("locale" , "text" , array()) + ->add("name" , "text" , array("constraints" => array(new NotBlank()))) + ->add("locale" , "text" , array("constraints" => array(new NotBlank()))) ->add("symbol" , "text" , array("constraints" => array(new NotBlank()))) ->add("rate" , "text" , array("constraints" => array(new NotBlank()))) - ->add("code" , "text" , array("constraints" => array(new NotBlank()))) + ->add("code" , "text" , array("constraints" => $code_constraints)) ; } @@ -53,12 +53,12 @@ class CurrencyCreationForm extends BaseForm return "thelia_currency_creation"; } - public function checkDuplicateName($value, ExecutionContextInterface $context) + public function checkDuplicateCode($value, ExecutionContextInterface $context) { - $currency = CurrencyQuery::create()->findOneByName($value); + $currency = CurrencyQuery::create()->findOneByCode($value); if ($currency) { - $context->addViolation(sprintf("A currency with name \"%s\" already exists.", $value)); + $context->addViolation(sprintf("A currency with code \"%s\" already exists.", $value)); } } diff --git a/core/lib/Thelia/Form/CurrencyModificationForm.php b/core/lib/Thelia/Form/CurrencyModificationForm.php index 6a4279d1b..3f0b1f152 100644 --- a/core/lib/Thelia/Form/CurrencyModificationForm.php +++ b/core/lib/Thelia/Form/CurrencyModificationForm.php @@ -34,8 +34,8 @@ class CurrencyModificationForm extends CurrencyCreationForm parent::buildForm(true); $this->formBuilder - ->add("id" , "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) - ; + ->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0))))) + ; } public function getName() diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php new file mode 100644 index 000000000..58c510267 --- /dev/null +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -0,0 +1,46 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Install; +use Thelia\Install\Exception\AlreadyInstallException; + +/** + * Class BaseInstall + * @author Manuel Raynaud + */ +abstract class BaseInstall +{ + /** + * Verify if an installation already exists + */ + public function __construct($verifyInstall = true) + { + if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { + throw new AlreadyInstallException("Thelia is already installed"); + } + + + $this->exec(); + } + + abstract public function exec(); +} \ No newline at end of file diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php new file mode 100644 index 000000000..db73330cf --- /dev/null +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -0,0 +1,78 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install; + + +/** + * Class CheckPermission + * @package Thelia\Install + * @author Manuel Raynaud + */ +class CheckPermission extends BaseInstall +{ + const CONF = "const"; + const LOG = "log"; + const CACHE = "cache"; + + private $directories = array(); + private $validation = array(); + private $valid = true; + + public function __construct($verifyInstall = true) + { + + + $this->directories = array( + self::CONF => THELIA_ROOT . "local/config", + self::LOG => THELIA_ROOT . "log", + self::CACHE => THELIA_ROOT . "cache" + ); + + $this->validation = array( + self::CONF => array( + "text" => sprintf("config directory(%s)...", $this->directories[self::CONF]), + "status" => true + ), + self::LOG => array( + "text" => sprintf("cache directory(%s)...", $this->directories[self::LOG]), + "status" => true + ), + self::CACHE => array( + "text" => sprintf("log directory(%s)...", $this->directories[self::CACHE]), + "status" => true + ) + ); + parent::__construct($verifyInstall); + } + + public function exec() + { + foreach ($this->directories as $key => $directory) { + if(is_writable($directory) === false) { + $this->valid = false; + $this->validation[$key]["status"] = false; + } + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Install/Database.php b/core/lib/Thelia/Install/Database.php new file mode 100644 index 000000000..34ca97dae --- /dev/null +++ b/core/lib/Thelia/Install/Database.php @@ -0,0 +1,103 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install; + + +/** + * Class Database + * @package Thelia\Install + * @author Manuel Raynaud + */ +class Database +{ + public $connection; + + public function __construct(\PDO $connection) + { + $this->connection = $connection; + } + + /** + * Insert all sql needed in database + * + * @param $dbName + */ + public function insertSql($dbName = null) + { + if($dbName) { + $this->connection->query(sprintf("use %s", $dbName)); + } + + $sql = array(); + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), + $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) + ); + + for ($i = 0; $i < count($sql); $i ++) { + if (!empty($sql[$i])) { + $this->connection->query($sql[$i]); + } + } + } + + /** + * Separate each sql instruction in an array + * + * @param $sql + * @return array + */ + protected function prepareSql($sql) + { + $sql = str_replace(";',", "-CODE-", $sql); + $sql = trim($sql); + $query = array(); + + $tab = explode(";", $sql); + + for ($i=0; $iconnection->query( + sprintf( + "CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8", + $dbName + ) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Install/Exception/AlreadyInstallException.php b/core/lib/Thelia/Install/Exception/AlreadyInstallException.php new file mode 100644 index 000000000..1409c7cdd --- /dev/null +++ b/core/lib/Thelia/Install/Exception/AlreadyInstallException.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install\Exception; + + +/** + * Class AlreadyInstallException + * @package Thelia\Install\Exception + * @author Manuel Raynaud + */ +class AlreadyInstallException extends InstallException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Install/Exception/InstallException.php b/core/lib/Thelia/Install/Exception/InstallException.php new file mode 100644 index 000000000..6924bcfe5 --- /dev/null +++ b/core/lib/Thelia/Install/Exception/InstallException.php @@ -0,0 +1,32 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Install\Exception; + +/** + * Class InstallException + * @author Manuel Raynaud + */ +class InstallException extends \RuntimeException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index 1edd6f4ff..58e6285ca 100755 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -2,8 +2,21 @@ namespace Thelia\Model; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Model\Base\Address as BaseAddress; class Address extends BaseAddress { + protected $dispatcher; + + public function setDispatcher(EventDispatcherInterface $dispatcher) + { + $this->dispatcher = $dispatcher; + } + + public function getDispatcher() + { + return $this->dispatcher; + } + } diff --git a/core/lib/Thelia/Model/Base/Address.php b/core/lib/Thelia/Model/Base/Address.php index a6ab068d1..2dc666a08 100644 --- a/core/lib/Thelia/Model/Base/Address.php +++ b/core/lib/Thelia/Model/Base/Address.php @@ -70,10 +70,10 @@ abstract class Address implements ActiveRecordInterface protected $id; /** - * The value for the name field. + * The value for the label field. * @var string */ - protected $name; + protected $label; /** * The value for the customer_id field. @@ -498,14 +498,14 @@ abstract class Address implements ActiveRecordInterface } /** - * Get the [name] column value. + * Get the [label] column value. * * @return string */ - public function getName() + public function getLabel() { - return $this->name; + return $this->label; } /** @@ -724,25 +724,25 @@ abstract class Address implements ActiveRecordInterface } // setId() /** - * Set the value of [name] column. + * Set the value of [label] column. * * @param string $v new value * @return \Thelia\Model\Address The current object (for fluent API support) */ - public function setName($v) + public function setLabel($v) { if ($v !== null) { $v = (string) $v; } - if ($this->name !== $v) { - $this->name = $v; - $this->modifiedColumns[] = AddressTableMap::NAME; + if ($this->label !== $v) { + $this->label = $v; + $this->modifiedColumns[] = AddressTableMap::LABEL; } return $this; - } // setName() + } // setLabel() /** * Set the value of [customer_id] column. @@ -1136,8 +1136,8 @@ abstract class Address implements ActiveRecordInterface $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : AddressTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; $this->id = (null !== $col) ? (int) $col : null; - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AddressTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; - $this->name = (null !== $col) ? (string) $col : null; + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : AddressTableMap::translateFieldName('Label', TableMap::TYPE_PHPNAME, $indexType)]; + $this->label = (null !== $col) ? (string) $col : null; $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : AddressTableMap::translateFieldName('CustomerId', TableMap::TYPE_PHPNAME, $indexType)]; $this->customer_id = (null !== $col) ? (int) $col : null; @@ -1501,8 +1501,8 @@ abstract class Address implements ActiveRecordInterface if ($this->isColumnModified(AddressTableMap::ID)) { $modifiedColumns[':p' . $index++] = 'ID'; } - if ($this->isColumnModified(AddressTableMap::NAME)) { - $modifiedColumns[':p' . $index++] = 'NAME'; + if ($this->isColumnModified(AddressTableMap::LABEL)) { + $modifiedColumns[':p' . $index++] = 'LABEL'; } if ($this->isColumnModified(AddressTableMap::CUSTOMER_ID)) { $modifiedColumns[':p' . $index++] = 'CUSTOMER_ID'; @@ -1566,8 +1566,8 @@ abstract class Address implements ActiveRecordInterface case 'ID': $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); break; - case 'NAME': - $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + case 'LABEL': + $stmt->bindValue($identifier, $this->label, PDO::PARAM_STR); break; case 'CUSTOMER_ID': $stmt->bindValue($identifier, $this->customer_id, PDO::PARAM_INT); @@ -1683,7 +1683,7 @@ abstract class Address implements ActiveRecordInterface return $this->getId(); break; case 1: - return $this->getName(); + return $this->getLabel(); break; case 2: return $this->getCustomerId(); @@ -1763,7 +1763,7 @@ abstract class Address implements ActiveRecordInterface $keys = AddressTableMap::getFieldNames($keyType); $result = array( $keys[0] => $this->getId(), - $keys[1] => $this->getName(), + $keys[1] => $this->getLabel(), $keys[2] => $this->getCustomerId(), $keys[3] => $this->getTitleId(), $keys[4] => $this->getCompany(), @@ -1841,7 +1841,7 @@ abstract class Address implements ActiveRecordInterface $this->setId($value); break; case 1: - $this->setName($value); + $this->setLabel($value); break; case 2: $this->setCustomerId($value); @@ -1916,7 +1916,7 @@ abstract class Address implements ActiveRecordInterface $keys = AddressTableMap::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setName($arr[$keys[1]]); + if (array_key_exists($keys[1], $arr)) $this->setLabel($arr[$keys[1]]); if (array_key_exists($keys[2], $arr)) $this->setCustomerId($arr[$keys[2]]); if (array_key_exists($keys[3], $arr)) $this->setTitleId($arr[$keys[3]]); if (array_key_exists($keys[4], $arr)) $this->setCompany($arr[$keys[4]]); @@ -1945,7 +1945,7 @@ abstract class Address implements ActiveRecordInterface $criteria = new Criteria(AddressTableMap::DATABASE_NAME); if ($this->isColumnModified(AddressTableMap::ID)) $criteria->add(AddressTableMap::ID, $this->id); - if ($this->isColumnModified(AddressTableMap::NAME)) $criteria->add(AddressTableMap::NAME, $this->name); + if ($this->isColumnModified(AddressTableMap::LABEL)) $criteria->add(AddressTableMap::LABEL, $this->label); if ($this->isColumnModified(AddressTableMap::CUSTOMER_ID)) $criteria->add(AddressTableMap::CUSTOMER_ID, $this->customer_id); if ($this->isColumnModified(AddressTableMap::TITLE_ID)) $criteria->add(AddressTableMap::TITLE_ID, $this->title_id); if ($this->isColumnModified(AddressTableMap::COMPANY)) $criteria->add(AddressTableMap::COMPANY, $this->company); @@ -2025,7 +2025,7 @@ abstract class Address implements ActiveRecordInterface */ public function copyInto($copyObj, $deepCopy = false, $makeNew = true) { - $copyObj->setName($this->getName()); + $copyObj->setLabel($this->getLabel()); $copyObj->setCustomerId($this->getCustomerId()); $copyObj->setTitleId($this->getTitleId()); $copyObj->setCompany($this->getCompany()); @@ -2804,7 +2804,7 @@ abstract class Address implements ActiveRecordInterface public function clear() { $this->id = null; - $this->name = null; + $this->label = null; $this->customer_id = null; $this->title_id = null; $this->company = null; diff --git a/core/lib/Thelia/Model/Base/AddressQuery.php b/core/lib/Thelia/Model/Base/AddressQuery.php index c67c79b02..dc6827868 100644 --- a/core/lib/Thelia/Model/Base/AddressQuery.php +++ b/core/lib/Thelia/Model/Base/AddressQuery.php @@ -22,7 +22,7 @@ use Thelia\Model\Map\AddressTableMap; * * * @method ChildAddressQuery orderById($order = Criteria::ASC) Order by the id column - * @method ChildAddressQuery orderByName($order = Criteria::ASC) Order by the name column + * @method ChildAddressQuery orderByLabel($order = Criteria::ASC) Order by the label column * @method ChildAddressQuery orderByCustomerId($order = Criteria::ASC) Order by the customer_id column * @method ChildAddressQuery orderByTitleId($order = Criteria::ASC) Order by the title_id column * @method ChildAddressQuery orderByCompany($order = Criteria::ASC) Order by the company column @@ -41,7 +41,7 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddressQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column * * @method ChildAddressQuery groupById() Group by the id column - * @method ChildAddressQuery groupByName() Group by the name column + * @method ChildAddressQuery groupByLabel() Group by the label column * @method ChildAddressQuery groupByCustomerId() Group by the customer_id column * @method ChildAddressQuery groupByTitleId() Group by the title_id column * @method ChildAddressQuery groupByCompany() Group by the company column @@ -87,7 +87,7 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddress findOneOrCreate(ConnectionInterface $con = null) Return the first ChildAddress matching the query, or a new ChildAddress object populated from the query conditions when no match is found * * @method ChildAddress findOneById(int $id) Return the first ChildAddress filtered by the id column - * @method ChildAddress findOneByName(string $name) Return the first ChildAddress filtered by the name column + * @method ChildAddress findOneByLabel(string $label) Return the first ChildAddress filtered by the label column * @method ChildAddress findOneByCustomerId(int $customer_id) Return the first ChildAddress filtered by the customer_id column * @method ChildAddress findOneByTitleId(int $title_id) Return the first ChildAddress filtered by the title_id column * @method ChildAddress findOneByCompany(string $company) Return the first ChildAddress filtered by the company column @@ -106,7 +106,7 @@ use Thelia\Model\Map\AddressTableMap; * @method ChildAddress findOneByUpdatedAt(string $updated_at) Return the first ChildAddress filtered by the updated_at column * * @method array findById(int $id) Return ChildAddress objects filtered by the id column - * @method array findByName(string $name) Return ChildAddress objects filtered by the name column + * @method array findByLabel(string $label) Return ChildAddress objects filtered by the label column * @method array findByCustomerId(int $customer_id) Return ChildAddress objects filtered by the customer_id column * @method array findByTitleId(int $title_id) Return ChildAddress objects filtered by the title_id column * @method array findByCompany(string $company) Return ChildAddress objects filtered by the company column @@ -211,7 +211,7 @@ abstract class AddressQuery extends ModelCriteria */ protected function findPkSimple($key, $con) { - $sql = 'SELECT ID, NAME, CUSTOMER_ID, TITLE_ID, COMPANY, FIRSTNAME, LASTNAME, ADDRESS1, ADDRESS2, ADDRESS3, ZIPCODE, CITY, COUNTRY_ID, PHONE, CELLPHONE, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM address WHERE ID = :p0'; + $sql = 'SELECT ID, LABEL, CUSTOMER_ID, TITLE_ID, COMPANY, FIRSTNAME, LASTNAME, ADDRESS1, ADDRESS2, ADDRESS3, ZIPCODE, CITY, COUNTRY_ID, PHONE, CELLPHONE, IS_DEFAULT, CREATED_AT, UPDATED_AT FROM address WHERE ID = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); @@ -342,32 +342,32 @@ abstract class AddressQuery extends ModelCriteria } /** - * Filter the query on the name column + * Filter the query on the label column * * Example usage: * - * $query->filterByName('fooValue'); // WHERE name = 'fooValue' - * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%' + * $query->filterByLabel('fooValue'); // WHERE label = 'fooValue' + * $query->filterByLabel('%fooValue%'); // WHERE label LIKE '%fooValue%' * * - * @param string $name The value to use as filter. + * @param string $label The value to use as filter. * Accepts wildcards (* and % trigger a LIKE) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildAddressQuery The current query, for fluid interface */ - public function filterByName($name = null, $comparison = null) + public function filterByLabel($label = null, $comparison = null) { if (null === $comparison) { - if (is_array($name)) { + if (is_array($label)) { $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $name)) { - $name = str_replace('*', '%', $name); + } elseif (preg_match('/[\%\*]/', $label)) { + $label = str_replace('*', '%', $label); $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(AddressTableMap::NAME, $name, $comparison); + return $this->addUsingAlias(AddressTableMap::LABEL, $label, $comparison); } /** diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index fbfbee32c..5ef6048a5 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -32,7 +32,7 @@ class CartItem extends BaseCartItem if ($this->dispatcher) { $cartEvent = new CartEvent($this->getCart()); - $this->dispatcher->dispatch(TheliaEvents::AFTER_CARTCHANGEITEM, $cartEvent); + $this->dispatcher->dispatch(TheliaEvents::AFTER_CARTUPDATEITEM, $cartEvent); } } diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index ae999ccc8..475481c2b 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -23,7 +23,7 @@ class Category extends BaseCategory public function getUrl($locale) { - return URL::retrieve('category', $this->getId(), $locale); + return URL::init()->retrieve('category', $this->getId(), $locale); } /** @@ -95,14 +95,14 @@ class Category extends BaseCategory public function preUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::BEFORE_CHANGECATEGORY, new CategoryEvent($this)); + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECATEGORY, new CategoryEvent($this)); return true; } public function postUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::AFTER_CHANGECATEGORY, new CategoryEvent($this)); + $this->dispatchEvent(TheliaEvents::AFTER_UPDATECATEGORY, new CategoryEvent($this)); } public function preDelete(ConnectionInterface $con = null) diff --git a/core/lib/Thelia/Model/Config.php b/core/lib/Thelia/Model/Config.php index 70880151c..a3289af27 100755 --- a/core/lib/Thelia/Model/Config.php +++ b/core/lib/Thelia/Model/Config.php @@ -55,7 +55,7 @@ class Config extends BaseConfig { */ public function preUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::BEFORE_CHANGECONFIG, new ConfigEvent($this)); + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECONFIG, new ConfigEvent($this)); return true; } @@ -65,7 +65,7 @@ class Config extends BaseConfig { */ public function postUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::AFTER_CHANGECONFIG, new ConfigEvent($this)); + $this->dispatchEvent(TheliaEvents::AFTER_UPDATECONFIG, new ConfigEvent($this)); } /** diff --git a/core/lib/Thelia/Model/ConfigQuery.php b/core/lib/Thelia/Model/ConfigQuery.php index 4165f4f7c..87b506e93 100755 --- a/core/lib/Thelia/Model/ConfigQuery.php +++ b/core/lib/Thelia/Model/ConfigQuery.php @@ -32,4 +32,14 @@ class ConfigQuery extends BaseConfigQuery { { return self::read("rewriting_enable") == 1; } + + public static function getPageNotFoundView() + { + return self::read("page_not_found_view", '404.html'); + } + + public static function getActiveTemplate() + { + return self::read('active-template', 'default'); + } } // ConfigQuery diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 1a797be89..f51915776 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -9,6 +9,6 @@ class Content extends BaseContent { public function getUrl($locale) { - return URL::retrieve('content', $this->getId(), $locale); + return URL::init()->retrieve('content', $this->getId(), $locale); } } diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index 6de6049ef..36f1ef8e1 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -23,8 +23,10 @@ namespace Thelia\Model; +use Propel\Runtime\Propel; use Thelia\Coupon\CouponRuleCollection; use Thelia\Model\Base\Coupon as BaseCoupon; +use Thelia\Model\Map\CouponTableMap; /** * Created by JetBrains PhpStorm. @@ -41,6 +43,58 @@ use Thelia\Model\Base\Coupon as BaseCoupon; */ class Coupon extends BaseCoupon { + + /** + * Constructor + * + * @param string $code Coupon Code + * @param string $title Coupon title + * @param float $amount Amount removed from the Total Checkout + * @param string $effect Coupon effect + * @param string $shortDescription Coupon short description + * @param string $description Coupon description + * @param boolean $isEnabled Enable/Disable + * @param \DateTime $expirationDate Coupon expiration date + * @param boolean $isAvailableOnSpecialOffers Is available on special offers + * @param boolean $isCumulative Is cumulative + * @param boolean $isRemovingPostage Is removing Postage + * @param int $maxUsage Coupon quantity + * @param CouponRuleCollection $rules CouponRuleInterface to add + * @param string $lang Coupon Language code ISO (ex: fr_FR) + */ + function createOrUpdate($code, $title, $amount, $effect, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $rules, $lang = null) + { + $this->setCode($code) + ->setTitle($title) + ->setShortDescription($shortDescription) + ->setDescription($description) + ->setType($effect) + ->setAmount($amount) + ->setType($amount) + ->setIsEnabled($isEnabled) + ->setExpirationDate($expirationDate) + ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) + ->setIsCumulative($isCumulative) + ->setMaxUsage($maxUsage) + ->setRules($rules); + + // Set object language (i18n) + if (!is_null($lang)) { + $this->setLang($lang); + } + + $con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME); + $con->beginTransaction(); + try { + $this->save($con); + $con->commit(); + + } catch(\Exception $e) { + $con->rollback(); + throw $e; + } + } + /** * Set the value of [serialized_rules] column. * @@ -50,19 +104,19 @@ class Coupon extends BaseCoupon */ public function setRules(CouponRuleCollection $rules) { + $serializedRules = null; if ($rules !== null) { - $v = (string) base64_encode(serialize($rules)); + $serializedRules = (string) base64_encode(serialize($rules)); } - if ($this->serialized_rules !== $v) { - $this->serialized_rules = $v; + if ($this->serialized_rules !== $serializedRules) { + $this->serialized_rules = $serializedRules; $this->modifiedColumns[] = CouponTableMap::SERIALIZED_RULES; } - return $this; - } // setSerializedRules() + } /** diff --git a/core/lib/Thelia/Model/Currency.php b/core/lib/Thelia/Model/Currency.php index f2f1175c6..fc1c86b67 100755 --- a/core/lib/Thelia/Model/Currency.php +++ b/core/lib/Thelia/Model/Currency.php @@ -34,7 +34,7 @@ class Currency extends BaseCurrency { */ public function preUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::BEFORE_CHANGECURRENCY, new CurrencyEvent($this)); + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECURRENCY, new CurrencyEvent($this)); return true; } @@ -44,7 +44,7 @@ class Currency extends BaseCurrency { */ public function postUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::AFTER_CHANGECURRENCY, new CurrencyEvent($this)); + $this->dispatchEvent(TheliaEvents::AFTER_UPDATECURRENCY, new CurrencyEvent($this)); } /** diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index 8f3de28d1..9572b6441 100755 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -3,6 +3,7 @@ namespace Thelia\Model; use Symfony\Component\Config\Definition\Exception\Exception; +use Thelia\Model\AddressQuery; use Thelia\Model\Base\Customer as BaseCustomer; use Thelia\Model\Exception\InvalidArgumentException; @@ -74,28 +75,46 @@ class Customer extends BaseCustomer implements UserInterface $con = Propel::getWriteConnection(CustomerTableMap::DATABASE_NAME); $con->beginTransaction(); try { + if ($this->isNew()) { + $address = new Address(); + + $address + ->setTitleId($titleId) + ->setFirstname($firstname) + ->setLastname($lastname) + ->setAddress1($address1) + ->setAddress2($address2) + ->setAddress3($address3) + ->setPhone($phone) + ->setCellphone($cellphone) + ->setZipcode($zipcode) + ->setCountryId($countryId) + ->setIsDefault(1) + ; + + $this->addAddress($address); + + } else { + $address = $this->getDefaultAddress(); + + $address + ->setTitleId($titleId) + ->setFirstname($firstname) + ->setLastname($lastname) + ->setAddress1($address1) + ->setAddress2($address2) + ->setAddress3($address3) + ->setPhone($phone) + ->setCellphone($cellphone) + ->setZipcode($zipcode) + ->setCountryId($countryId) + ->save($con) + ; + } $this->save($con); - $address = new Address(); - - $address - ->setTitleId($titleId) - ->setFirstname($firstname) - ->setLastname($lastname) - ->setAddress1($address1) - ->setAddress2($address2) - ->setAddress3($address3) - ->setPhone($phone) - ->setCellphone($cellphone) - ->setZipcode($zipcode) - ->setCountryId($countryId) - ->setIsDefault(1) - ->setCustomer($this) - ->save($con); - $con->commit(); - } catch(Exception $e) { $con->rollback(); throw $e; @@ -107,12 +126,23 @@ class Customer extends BaseCustomer implements UserInterface return uniqid(substr($this->getLastname(), 0, (strlen($this->getLastname()) >= 3) ? 3 : strlen($this->getLastname())), true); } + /** + * @return Address + */ + public function getDefaultAddress() + { + return AddressQuery::create() + ->filterByCustomer($this) + ->filterByIsDefault(1) + ->findOne(); + } + /** * create hash for plain password and set it in Customer object * * @param string $password plain password before hashing + * @throws Exception\InvalidArgumentException * @return $this|Customer - * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function setPassword($password) { diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 05838e939..2672c17de 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -17,7 +17,7 @@ class Folder extends BaseFolder public function getUrl($locale) { - return URL::retrieve('folder', $this->getId(), $locale); + return URL::init()->retrieve('folder', $this->getId(), $locale); } /** diff --git a/core/lib/Thelia/Model/Map/AddressTableMap.php b/core/lib/Thelia/Model/Map/AddressTableMap.php index dabd6a54e..46e2be02d 100644 --- a/core/lib/Thelia/Model/Map/AddressTableMap.php +++ b/core/lib/Thelia/Model/Map/AddressTableMap.php @@ -75,9 +75,9 @@ class AddressTableMap extends TableMap const ID = 'address.ID'; /** - * the column name for the NAME field + * the column name for the LABEL field */ - const NAME = 'address.NAME'; + const LABEL = 'address.LABEL'; /** * the column name for the CUSTOMER_ID field @@ -171,11 +171,11 @@ class AddressTableMap extends TableMap * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ protected static $fieldNames = array ( - self::TYPE_PHPNAME => array('Id', 'Name', 'CustomerId', 'TitleId', 'Company', 'Firstname', 'Lastname', 'Address1', 'Address2', 'Address3', 'Zipcode', 'City', 'CountryId', 'Phone', 'Cellphone', 'IsDefault', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'name', 'customerId', 'titleId', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'countryId', 'phone', 'cellphone', 'isDefault', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(AddressTableMap::ID, AddressTableMap::NAME, AddressTableMap::CUSTOMER_ID, AddressTableMap::TITLE_ID, AddressTableMap::COMPANY, AddressTableMap::FIRSTNAME, AddressTableMap::LASTNAME, AddressTableMap::ADDRESS1, AddressTableMap::ADDRESS2, AddressTableMap::ADDRESS3, AddressTableMap::ZIPCODE, AddressTableMap::CITY, AddressTableMap::COUNTRY_ID, AddressTableMap::PHONE, AddressTableMap::CELLPHONE, AddressTableMap::IS_DEFAULT, AddressTableMap::CREATED_AT, AddressTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'NAME', 'CUSTOMER_ID', 'TITLE_ID', 'COMPANY', 'FIRSTNAME', 'LASTNAME', 'ADDRESS1', 'ADDRESS2', 'ADDRESS3', 'ZIPCODE', 'CITY', 'COUNTRY_ID', 'PHONE', 'CELLPHONE', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'name', 'customer_id', 'title_id', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'country_id', 'phone', 'cellphone', 'is_default', 'created_at', 'updated_at', ), + self::TYPE_PHPNAME => array('Id', 'Label', 'CustomerId', 'TitleId', 'Company', 'Firstname', 'Lastname', 'Address1', 'Address2', 'Address3', 'Zipcode', 'City', 'CountryId', 'Phone', 'Cellphone', 'IsDefault', 'CreatedAt', 'UpdatedAt', ), + self::TYPE_STUDLYPHPNAME => array('id', 'label', 'customerId', 'titleId', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'countryId', 'phone', 'cellphone', 'isDefault', 'createdAt', 'updatedAt', ), + self::TYPE_COLNAME => array(AddressTableMap::ID, AddressTableMap::LABEL, AddressTableMap::CUSTOMER_ID, AddressTableMap::TITLE_ID, AddressTableMap::COMPANY, AddressTableMap::FIRSTNAME, AddressTableMap::LASTNAME, AddressTableMap::ADDRESS1, AddressTableMap::ADDRESS2, AddressTableMap::ADDRESS3, AddressTableMap::ZIPCODE, AddressTableMap::CITY, AddressTableMap::COUNTRY_ID, AddressTableMap::PHONE, AddressTableMap::CELLPHONE, AddressTableMap::IS_DEFAULT, AddressTableMap::CREATED_AT, AddressTableMap::UPDATED_AT, ), + self::TYPE_RAW_COLNAME => array('ID', 'LABEL', 'CUSTOMER_ID', 'TITLE_ID', 'COMPANY', 'FIRSTNAME', 'LASTNAME', 'ADDRESS1', 'ADDRESS2', 'ADDRESS3', 'ZIPCODE', 'CITY', 'COUNTRY_ID', 'PHONE', 'CELLPHONE', 'IS_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ), + self::TYPE_FIELDNAME => array('id', 'label', 'customer_id', 'title_id', 'company', 'firstname', 'lastname', 'address1', 'address2', 'address3', 'zipcode', 'city', 'country_id', 'phone', 'cellphone', 'is_default', 'created_at', 'updated_at', ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ) ); @@ -186,11 +186,11 @@ class AddressTableMap extends TableMap * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 */ protected static $fieldKeys = array ( - self::TYPE_PHPNAME => array('Id' => 0, 'Name' => 1, 'CustomerId' => 2, 'TitleId' => 3, 'Company' => 4, 'Firstname' => 5, 'Lastname' => 6, 'Address1' => 7, 'Address2' => 8, 'Address3' => 9, 'Zipcode' => 10, 'City' => 11, 'CountryId' => 12, 'Phone' => 13, 'Cellphone' => 14, 'IsDefault' => 15, 'CreatedAt' => 16, 'UpdatedAt' => 17, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'name' => 1, 'customerId' => 2, 'titleId' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'countryId' => 12, 'phone' => 13, 'cellphone' => 14, 'isDefault' => 15, 'createdAt' => 16, 'updatedAt' => 17, ), - self::TYPE_COLNAME => array(AddressTableMap::ID => 0, AddressTableMap::NAME => 1, AddressTableMap::CUSTOMER_ID => 2, AddressTableMap::TITLE_ID => 3, AddressTableMap::COMPANY => 4, AddressTableMap::FIRSTNAME => 5, AddressTableMap::LASTNAME => 6, AddressTableMap::ADDRESS1 => 7, AddressTableMap::ADDRESS2 => 8, AddressTableMap::ADDRESS3 => 9, AddressTableMap::ZIPCODE => 10, AddressTableMap::CITY => 11, AddressTableMap::COUNTRY_ID => 12, AddressTableMap::PHONE => 13, AddressTableMap::CELLPHONE => 14, AddressTableMap::IS_DEFAULT => 15, AddressTableMap::CREATED_AT => 16, AddressTableMap::UPDATED_AT => 17, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'NAME' => 1, 'CUSTOMER_ID' => 2, 'TITLE_ID' => 3, 'COMPANY' => 4, 'FIRSTNAME' => 5, 'LASTNAME' => 6, 'ADDRESS1' => 7, 'ADDRESS2' => 8, 'ADDRESS3' => 9, 'ZIPCODE' => 10, 'CITY' => 11, 'COUNTRY_ID' => 12, 'PHONE' => 13, 'CELLPHONE' => 14, 'IS_DEFAULT' => 15, 'CREATED_AT' => 16, 'UPDATED_AT' => 17, ), - self::TYPE_FIELDNAME => array('id' => 0, 'name' => 1, 'customer_id' => 2, 'title_id' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'country_id' => 12, 'phone' => 13, 'cellphone' => 14, 'is_default' => 15, 'created_at' => 16, 'updated_at' => 17, ), + self::TYPE_PHPNAME => array('Id' => 0, 'Label' => 1, 'CustomerId' => 2, 'TitleId' => 3, 'Company' => 4, 'Firstname' => 5, 'Lastname' => 6, 'Address1' => 7, 'Address2' => 8, 'Address3' => 9, 'Zipcode' => 10, 'City' => 11, 'CountryId' => 12, 'Phone' => 13, 'Cellphone' => 14, 'IsDefault' => 15, 'CreatedAt' => 16, 'UpdatedAt' => 17, ), + self::TYPE_STUDLYPHPNAME => array('id' => 0, 'label' => 1, 'customerId' => 2, 'titleId' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'countryId' => 12, 'phone' => 13, 'cellphone' => 14, 'isDefault' => 15, 'createdAt' => 16, 'updatedAt' => 17, ), + self::TYPE_COLNAME => array(AddressTableMap::ID => 0, AddressTableMap::LABEL => 1, AddressTableMap::CUSTOMER_ID => 2, AddressTableMap::TITLE_ID => 3, AddressTableMap::COMPANY => 4, AddressTableMap::FIRSTNAME => 5, AddressTableMap::LASTNAME => 6, AddressTableMap::ADDRESS1 => 7, AddressTableMap::ADDRESS2 => 8, AddressTableMap::ADDRESS3 => 9, AddressTableMap::ZIPCODE => 10, AddressTableMap::CITY => 11, AddressTableMap::COUNTRY_ID => 12, AddressTableMap::PHONE => 13, AddressTableMap::CELLPHONE => 14, AddressTableMap::IS_DEFAULT => 15, AddressTableMap::CREATED_AT => 16, AddressTableMap::UPDATED_AT => 17, ), + self::TYPE_RAW_COLNAME => array('ID' => 0, 'LABEL' => 1, 'CUSTOMER_ID' => 2, 'TITLE_ID' => 3, 'COMPANY' => 4, 'FIRSTNAME' => 5, 'LASTNAME' => 6, 'ADDRESS1' => 7, 'ADDRESS2' => 8, 'ADDRESS3' => 9, 'ZIPCODE' => 10, 'CITY' => 11, 'COUNTRY_ID' => 12, 'PHONE' => 13, 'CELLPHONE' => 14, 'IS_DEFAULT' => 15, 'CREATED_AT' => 16, 'UPDATED_AT' => 17, ), + self::TYPE_FIELDNAME => array('id' => 0, 'label' => 1, 'customer_id' => 2, 'title_id' => 3, 'company' => 4, 'firstname' => 5, 'lastname' => 6, 'address1' => 7, 'address2' => 8, 'address3' => 9, 'zipcode' => 10, 'city' => 11, 'country_id' => 12, 'phone' => 13, 'cellphone' => 14, 'is_default' => 15, 'created_at' => 16, 'updated_at' => 17, ), self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ) ); @@ -211,7 +211,7 @@ class AddressTableMap extends TableMap $this->setUseIdGenerator(true); // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null); + $this->addColumn('LABEL', 'Label', 'VARCHAR', false, 255, null); $this->addForeignKey('CUSTOMER_ID', 'CustomerId', 'INTEGER', 'customer', 'ID', true, null, null); $this->addForeignKey('TITLE_ID', 'TitleId', 'INTEGER', 'customer_title', 'ID', true, null, null); $this->addColumn('COMPANY', 'Company', 'VARCHAR', false, 255, null); @@ -394,7 +394,7 @@ class AddressTableMap extends TableMap { if (null === $alias) { $criteria->addSelectColumn(AddressTableMap::ID); - $criteria->addSelectColumn(AddressTableMap::NAME); + $criteria->addSelectColumn(AddressTableMap::LABEL); $criteria->addSelectColumn(AddressTableMap::CUSTOMER_ID); $criteria->addSelectColumn(AddressTableMap::TITLE_ID); $criteria->addSelectColumn(AddressTableMap::COMPANY); @@ -413,7 +413,7 @@ class AddressTableMap extends TableMap $criteria->addSelectColumn(AddressTableMap::UPDATED_AT); } else { $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.NAME'); + $criteria->addSelectColumn($alias . '.LABEL'); $criteria->addSelectColumn($alias . '.CUSTOMER_ID'); $criteria->addSelectColumn($alias . '.TITLE_ID'); $criteria->addSelectColumn($alias . '.COMPANY'); diff --git a/core/lib/Thelia/Model/Message.php b/core/lib/Thelia/Model/Message.php index 97fb45469..aa6481ab8 100755 --- a/core/lib/Thelia/Model/Message.php +++ b/core/lib/Thelia/Model/Message.php @@ -34,7 +34,7 @@ class Message extends BaseMessage { */ public function preUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::BEFORE_CHANGEMESSAGE, new MessageEvent($this)); + $this->dispatchEvent(TheliaEvents::BEFORE_UPDATEMESSAGE, new MessageEvent($this)); return true; } @@ -44,7 +44,7 @@ class Message extends BaseMessage { */ public function postUpdate(ConnectionInterface $con = null) { - $this->dispatchEvent(TheliaEvents::AFTER_CHANGEMESSAGE, new MessageEvent($this)); + $this->dispatchEvent(TheliaEvents::AFTER_UPDATEMESSAGE, new MessageEvent($this)); } /** diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index e7d0586cc..b4b036896 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -9,6 +9,6 @@ class Product extends BaseProduct { public function getUrl($locale) { - return URL::retrieve('product', $this->getId(), $locale); + return URL::init()->retrieve('product', $this->getId(), $locale); } } diff --git a/core/lib/Thelia/Model/RewritingUrlQuery.php b/core/lib/Thelia/Model/RewritingUrlQuery.php index c5b73c1e5..d1ab8fcdf 100644 --- a/core/lib/Thelia/Model/RewritingUrlQuery.php +++ b/core/lib/Thelia/Model/RewritingUrlQuery.php @@ -2,8 +2,10 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\ActiveQuery\Join; use Thelia\Model\Base\RewritingUrlQuery as BaseRewritingUrlQuery; - +use Thelia\Model\Map\RewritingUrlTableMap; /** * Skeleton subclass for performing query and update operations on the 'rewriting_url' table. @@ -15,6 +17,96 @@ use Thelia\Model\Base\RewritingUrlQuery as BaseRewritingUrlQuery; * long as it does not already exist in the output directory. * */ -class RewritingUrlQuery extends BaseRewritingUrlQuery { +class RewritingUrlQuery extends BaseRewritingUrlQuery +{ + /** + * @param $rewrittenUrl + * + * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection + */ + public function getResolverSearch($rewrittenUrl) + { + $redirectedJoin = new Join(); + $redirectedJoin->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'REDIRECTED', 'ru', RewritingUrlTableMap::TABLE_NAME, 'ID', 'is_redirected'); + $redirectedJoin->setJoinType(Criteria::LEFT_JOIN); + $search = RewritingArgumentQuery::create() + ->joinRewritingUrl('ru', Criteria::RIGHT_JOIN) + ->addJoinObject($redirectedJoin) + ->where('`ru`.URL = ?', $rewrittenUrl, \PDO::PARAM_STR) + ->withColumn('`ru`.URL', 'ru_url') + ->withColumn('`ru`.VIEW', 'ru_view') + ->withColumn('`ru`.VIEW_LOCALE', 'ru_locale') + ->withColumn('`ru`.VIEW_ID', 'ru_viewId') + ->withColumn('`is_redirected`.URL', 'ru_redirected_to_url') + ->find(); + + return $search; + } + + /** + * @param $view + * @param $viewId + * @param $viewLocale + * + * @return null|RewritingUrl + */ + public function getViewUrlQuery($view, $viewLocale, $viewId) + { + return RewritingUrlQuery::create() + ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) + ->where('ISNULL(`ra`.REWRITING_URL_ID)') + ->filterByView($view) + ->filterByViewLocale($viewLocale) + ->filterByViewId($viewId) + ->filterByRedirected(null) + ->orderByUpdatedAt(Criteria::DESC) + ->findOne(); + } + + /** + * @param $view + * @param $viewLocale + * @param $viewId + * @param $viewOtherParameters + * + * @return null|RewritingUrl + */ + public function getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters) + { + $urlQuery = RewritingUrlQuery::create() + ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) + ->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID') + ->filterByView($view) + ->filterByViewLocale($viewLocale) + ->filterByViewId($viewId) + ->filterByRedirected(null) + ->orderByUpdatedAt(Criteria::DESC); + + $otherParametersCount = count($viewOtherParameters); + if($otherParametersCount > 0) { + $parameterConditions = array(); + + foreach($viewOtherParameters as $parameter => $value) { + $conditionName = 'other_parameter_condition_' . count($parameterConditions); + $urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR) + ->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR) + ->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName); + $parameterConditions[] = $conditionName; + } + + $urlQuery->where($parameterConditions, Criteria::LOGICAL_OR); + + $urlQuery->groupBy(RewritingUrlTableMap::ID); + + $urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query) + ->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url) + + $urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND); + } else { + $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); + } + + return $urlQuery->findOne(); + } } // RewritingUrlQuery diff --git a/core/lib/Thelia/Rewriting/RewritingResolver.php b/core/lib/Thelia/Rewriting/RewritingResolver.php index 818dbec32..900442db9 100755 --- a/core/lib/Thelia/Rewriting/RewritingResolver.php +++ b/core/lib/Thelia/Rewriting/RewritingResolver.php @@ -22,6 +22,13 @@ /*************************************************************************************/ namespace Thelia\Rewriting; +use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\ActiveQuery\Join; +use Thelia\Exception\RewritingUrlException; +use Thelia\Exception\UrlRewritingException; +use Thelia\Model\RewritingUrlQuery; +use Thelia\Model\Map\RewritingUrlTableMap; + /** * Class RewritingResolver * @package Thelia\Rewriting @@ -31,5 +38,58 @@ namespace Thelia\Rewriting; */ class RewritingResolver { + protected $search = null; + protected $rewritingUrlQuery = null; + + public $view; + public $viewId; + public $locale; + public $otherParameters; + public $redirectedToUrl; + + public function __construct($url = null) + { + $this->rewritingUrlQuery = new RewritingUrlQuery(); + + if($url !== null) { + $this->load($url); + } + } + + public function load($rewrittenUrl) + { + $this->search = $this->rewritingUrlQuery->getResolverSearch($rewrittenUrl); + + if($this->search->count() == 0) { + throw new UrlRewritingException('URL NOT FOUND', UrlRewritingException::URL_NOT_FOUND); + } + + $this->view = $this->search->getFirst()->getVirtualColumn('ru_view'); + $this->viewId = $this->search->getFirst()->getVirtualColumn('ru_viewId'); + $this->locale = $this->search->getFirst()->getVirtualColumn('ru_locale'); + $this->redirectedToUrl = $this->search->getFirst()->getVirtualColumn('ru_redirected_to_url'); + + $this->otherParameters = $this->getOtherParameters(); + } + + protected function getOtherParameters() + { + if($this->search === null) { + throw new UrlRewritingException('RESOLVER NULL SEARCH', UrlRewritingException::RESOLVER_NULL_SEARCH); + } + + $otherParameters = array(); + foreach($this->search as $result) { + $parameter = $result->getParameter(); + $value = $result->getValue(); + + if(null !== $parameter) { + $otherParameters[$parameter] = $value; + } + } + + return $otherParameters; + } + } diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index 0deb7de45..7958af012 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -23,8 +23,9 @@ namespace Thelia\Rewriting; use Propel\Runtime\ActiveQuery\Criteria; -use Thelia\Model\Base\RewritingUrlQuery; +use Thelia\Model\RewritingUrlQuery; use Thelia\Model\Map\RewritingUrlTableMap; +use Thelia\Tools\URL; /** * Class RewritingRetriever @@ -35,38 +36,40 @@ use Thelia\Model\Map\RewritingUrlTableMap; */ class RewritingRetriever { - /** - * @param $view - * @param $viewLocale - * @param $viewId - * - * @return null|$url - */ - public function getViewUrl($view, $viewLocale, $viewId) - { - $url = $this->getViewUrlQuery($view, $viewId, $viewLocale); + protected $search = null; + protected $rewritingUrlQuery = null; - return $url === null ? null : $url->getUrl(); + public $url; + public $rewrittenUrl; + + public function __construct($view = null, $viewLocale = null, $viewId = null) + { + $this->rewritingUrlQuery = new RewritingUrlQuery(); + + if($view !== null && $viewLocale !== null) { + $this->load($view, $viewLocale, $viewId); + } } /** - * @param $view - * @param $viewId - * @param $viewLocale - * - * @return null|RewritingUrl + * @param $view + * @param $viewLocale + * @param null $viewId */ - protected function getViewUrlQuery($view, $viewId, $viewLocale) + public function loadViewUrl($view, $viewLocale, $viewId = null) { - return RewritingUrlQuery::create() - ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) - ->where('ISNULL(`ra`.REWRITING_URL_ID)') - ->filterByView($view) - ->filterByViewLocale($viewLocale) - ->filterByViewId($viewId) - ->filterByRedirected(null) - ->orderByUpdatedAt(Criteria::DESC) - ->findOne(); + $this->search = $this->rewritingUrlQuery->getViewUrlQuery($view, $viewLocale, $viewId); + + $allParametersWithoutView = array(); + $allParametersWithoutView['locale'] = $viewLocale; + if(null !== $viewId) { + $allParametersWithoutView[$view . '_id'] = $viewId; + } + + $this->url = URL::viewUrl($view, $allParametersWithoutView); + if($this->search !== null) { + $this->rewrittenUrl = $this->search->getUrl(); + } } /** @@ -74,46 +77,25 @@ class RewritingRetriever * @param $viewLocale * @param null $viewId * @param array $viewOtherParameters - * - * @return null|$url */ - public function getSpecificUrl($view, $viewLocale, $viewId = null, $viewOtherParameters = array()) + public function loadSpecificUrl($view, $viewLocale, $viewId = null, $viewOtherParameters = array()) { - $urlQuery = RewritingUrlQuery::create() - ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) - ->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID') - ->filterByView($view) - ->filterByViewLocale($viewLocale) - ->filterByViewId($viewId) - ->filterByRedirected(null) - ->orderByUpdatedAt(Criteria::DESC); - - $otherParametersCount = count($viewOtherParameters); - if($otherParametersCount > 0) { - $parameterConditions = array(); - - foreach($viewOtherParameters as $parameter => $value) { - $conditionName = 'other_parameter_condition_' . count($parameterConditions); - $urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR) - ->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR) - ->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName); - $parameterConditions[] = $conditionName; - } - - $urlQuery->where($parameterConditions, Criteria::LOGICAL_OR); - - $urlQuery->groupBy(RewritingUrlTableMap::ID); - - $urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query) - ->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url) - - $urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND); - } else { - $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); + if(empty($viewOtherParameters)) { + $this->loadViewUrl($view, $viewLocale, $viewId); + return; } - $url = $urlQuery->findOne(); + $this->search = $this->rewritingUrlQuery->getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters); - return $url === null ? null : $url->getUrl(); + $allParametersWithoutView = $viewOtherParameters; + $allParametersWithoutView['locale'] = $viewLocale; + if(null !== $viewId) { + $allParametersWithoutView[$view . '_id'] = $viewId; + } + + $this->url = URL::viewUrl($view, $allParametersWithoutView); + if($this->search !== null) { + $this->rewrittenUrl = $this->search->getUrl(); + } } } diff --git a/core/lib/Thelia/Tests/Action/AddressTest.php b/core/lib/Thelia/Tests/Action/AddressTest.php new file mode 100644 index 000000000..68fc97923 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AddressTest.php @@ -0,0 +1,145 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; +use Thelia\Action\Address; +use Thelia\Core\Event\AddressCreateOrUpdateEvent; +use Thelia\Model\Base\CustomerQuery; + + +/** + * + * test address eventListener + * + * Class AddressTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class AddressTest extends \PHPUnit_Framework_TestCase +{ + + public function getContainer() + { + $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); + + $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + + $container->set("event_dispatcher", $dispatcher); + + return $container; + } + + public function testCreatedAddress() + { + $customer = CustomerQuery::create()->findOne(); + + $AddressCreateOrUpdateEvent = new AddressCreateOrUpdateEvent( + "test address", + 1, + "Thelia", + "Thelia", + "5 rue rochon", + "", + "", + "63000", + "clermont-ferrand", + 64, + "0102030405", + "", + "" + ); + $AddressCreateOrUpdateEvent->setCustomer($customer); + + $actionAddress = new Address($this->getContainer()); + $actionAddress->create($AddressCreateOrUpdateEvent); + + $createdAddress = $AddressCreateOrUpdateEvent->getAddress(); + + $this->assertInstanceOf("Thelia\Model\Address", $createdAddress); + $this->assertFalse($createdAddress->isNew()); + $this->assertSame($customer, $createdAddress->getCustomer()); + + $this->assertEquals($AddressCreateOrUpdateEvent->getLabel(), $createdAddress->getLabel()); + $this->assertEquals($AddressCreateOrUpdateEvent->getTitle(), $createdAddress->getTitleId()); + $this->assertEquals($AddressCreateOrUpdateEvent->getFirstname(), $createdAddress->getFirstname()); + $this->assertEquals($AddressCreateOrUpdateEvent->getLastname(), $createdAddress->getLastname()); + $this->assertEquals($AddressCreateOrUpdateEvent->getAddress1(), $createdAddress->getAddress1()); + $this->assertEquals($AddressCreateOrUpdateEvent->getAddress2(), $createdAddress->getAddress2()); + $this->assertEquals($AddressCreateOrUpdateEvent->getAddress3(), $createdAddress->getAddress3()); + $this->assertEquals($AddressCreateOrUpdateEvent->getZipcode(), $createdAddress->getZipcode()); + $this->assertEquals($AddressCreateOrUpdateEvent->getCity(), $createdAddress->getCity()); + $this->assertEquals($AddressCreateOrUpdateEvent->getCountry(), $createdAddress->getCountryId()); + $this->assertEquals($AddressCreateOrUpdateEvent->getPhone(), $createdAddress->getPhone()); + $this->assertEquals($AddressCreateOrUpdateEvent->getCellphone(), $createdAddress->getCellphone()); + $this->assertEquals($AddressCreateOrUpdateEvent->getCompany(), $createdAddress->getCompany()); + } + + public function testUpdatedAddress() + { + + $customer = CustomerQuery::create()->findOne(); + $address = $customer->getAddresses()->getFirst(); + + $addressEvent = new AddressCreateOrUpdateEvent( + "", + 1, + "Thelia modif", + "Thelia modif", + "cour des étoiles", + "rue des miracles", + "", + "63000", + "clermont-ferrand", + 64, + "0102030405", + "", + "" + ); + $addressEvent->setAddress($address); + + $actionAddress = new Address($this->getContainer()); + $actionAddress->update($addressEvent); + + + $updatedAddress = $addressEvent->getAddress(); + $this->assertInstanceOf("Thelia\Model\Address", $updatedAddress); + $this->assertFalse($updatedAddress->isNew()); + $this->assertSame($customer, $updatedAddress->getCustomer()); + + $this->assertEquals($address->getLabel(), $updatedAddress->getLabel()); + $this->assertEquals($addressEvent->getTitle(), $updatedAddress->getTitleId()); + $this->assertEquals($addressEvent->getFirstname(), $updatedAddress->getFirstname()); + $this->assertEquals($addressEvent->getLastname(), $updatedAddress->getLastname()); + $this->assertEquals($addressEvent->getAddress1(), $updatedAddress->getAddress1()); + $this->assertEquals($addressEvent->getAddress2(), $updatedAddress->getAddress2()); + $this->assertEquals($addressEvent->getAddress3(), $updatedAddress->getAddress3()); + $this->assertEquals($addressEvent->getZipcode(), $updatedAddress->getZipcode()); + $this->assertEquals($addressEvent->getCity(), $updatedAddress->getCity()); + $this->assertEquals($addressEvent->getCountry(), $updatedAddress->getCountryId()); + $this->assertEquals($addressEvent->getPhone(), $updatedAddress->getPhone()); + $this->assertEquals($addressEvent->getCellphone(), $updatedAddress->getCellphone()); + $this->assertEquals($addressEvent->getCompany(), $updatedAddress->getCompany()); + + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Rewriting/RewritingResolverTest.php b/core/lib/Thelia/Tests/Rewriting/RewritingResolverTest.php new file mode 100755 index 000000000..a3ec561d2 --- /dev/null +++ b/core/lib/Thelia/Tests/Rewriting/RewritingResolverTest.php @@ -0,0 +1,154 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Rewriting; + +use Thelia\Model\RewritingArgument; +use Thelia\Rewriting\RewritingResolver; +use Propel\Runtime\Collection\ObjectCollection; + +/** + * + * @author Etienne Roudeix + * + */ +class RewritingResolverTest extends \PHPUnit_Framework_TestCase +{ + protected function getMethod($name) + { + $class = new \ReflectionClass('\Thelia\Rewriting\RewritingResolver'); + $method = $class->getMethod($name); + $method->setAccessible(true); + + return $method; + } + + protected function getProperty($name) + { + $class = new \ReflectionClass('\Thelia\Rewriting\RewritingResolver'); + $property = $class->getProperty($name); + $property->setAccessible(true); + + return $property; + } + + /** + * @expectedException \Thelia\Exception\UrlRewritingException + * @expectedExceptionCode 800 + */ + public function testGetOtherParametersException() + { + $resolver = new RewritingResolver(); + + $method = $this->getMethod('getOtherParameters'); + $actual = $method->invoke($resolver); + } + + public function testGetOtherParameters() + { + $rewritingArguments = array( + array('Parameter' => 'foo0', 'Value' => 'bar0'), + array('Parameter' => 'foo1', 'Value' => 'bar1'), + array('Parameter' => 'foo2', 'Value' => 'bar2'), + ); + $searchResult = new ObjectCollection(); + $searchResult->setModel('\Thelia\Model\RewritingArgument'); + $searchResult->fromArray($rewritingArguments); + + $resolver = new RewritingResolver(); + + $search = $this->getProperty('search'); + $search->setValue($resolver, $searchResult); + + $method = $this->getMethod('getOtherParameters'); + $actual = $method->invoke($resolver); + + $expected = array( + 'foo0' => 'bar0', + 'foo1' => 'bar1', + 'foo2' => 'bar2', + ); + + $this->assertEquals($expected, $actual); + } + + /** + * @expectedException \Thelia\Exception\UrlRewritingException + * @expectedExceptionCode 404 + */ + public function testLoadException() + { + $collection = new ObjectCollection(); + $collection->setModel('\Thelia\Model\RewritingArgument'); + + $resolverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getResolverSearch')); + $resolverQuery->expects($this->any()) + ->method('getResolverSearch') + ->with('foo.html') + ->will($this->returnValue($collection)); + + $resolver = new RewritingResolver(); + + $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery'); + $rewritingUrlQuery->setValue($resolver, $resolverQuery); + + $resolver->load('foo.html'); + } + + public function testLoad() + { + $collection = new ObjectCollection(); + $collection->setModel('\Thelia\Model\RewritingArgument'); + + for($i=0; $i<3; $i++) { + $ra = new RewritingArgument(); + $ra->setParameter('foo' . $i); + $ra->setValue('bar' . $i); + $ra->setVirtualColumn('ru_view', 'view'); + $ra->setVirtualColumn('ru_viewId', 'viewId'); + $ra->setVirtualColumn('ru_locale', 'locale'); + $ra->setVirtualColumn('ru_redirected_to_url', null); + + $collection->append($ra); + } + + + $resolverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getResolverSearch')); + $resolverQuery->expects($this->any()) + ->method('getResolverSearch') + ->with('foo.html') + ->will($this->returnValue($collection)); + + $resolver = new RewritingResolver(); + + $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery'); + $rewritingUrlQuery->setValue($resolver, $resolverQuery); + + $resolver->load('foo.html'); + + $this->assertEquals('view', $resolver->view); + $this->assertEquals('viewId', $resolver->viewId); + $this->assertEquals('locale', $resolver->locale); + $this->assertEquals(array('foo0' => 'bar0', 'foo1' => 'bar1', 'foo2' => 'bar2'), $resolver->otherParameters); + } +} diff --git a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php index 741c22b4e..9a5036adc 100755 --- a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php +++ b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php @@ -23,7 +23,9 @@ namespace Thelia\Tests\Rewriting; +use Thelia\Model\RewritingUrl; use Thelia\Rewriting\RewritingRetriever; +use Thelia\Tools\URL; /** * @@ -32,13 +34,65 @@ use Thelia\Rewriting\RewritingRetriever; */ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase { - public function testGetViewUrl() + protected function getMethod($name) { + $class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; } - public function testGetSpecificUrl() + protected function getProperty($name) { + $class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever'); + $property = $class->getProperty($name); + $property->setAccessible(true); + return $property; + } + + public function testLoadViewUrl() + { + $searchResult = new RewritingUrl(); + $searchResult->setUrl('foo.html'); + + $retrieverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getViewUrlQuery')); + $retrieverQuery->expects($this->any()) + ->method('getViewUrlQuery') + ->with('view', 'fr_FR', 1) + ->will($this->returnValue($searchResult)); + + $retriever = new RewritingRetriever(); + + $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery'); + $rewritingUrlQuery->setValue($retriever, $retrieverQuery); + + $retriever->loadViewUrl('view', 'fr_FR', 1); + + $this->assertEquals('foo.html', $retriever->rewrittenUrl); + $this->assertEquals(URL::viewUrl('view', array('locale' => 'fr_FR', 'view_id' => 1)), $retriever->url); + } + + public function testLoadSpecificUrl() + { + $searchResult = new RewritingUrl(); + $searchResult->setUrl('foo.html'); + + $retrieverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getSpecificUrlQuery')); + $retrieverQuery->expects($this->any()) + ->method('getSpecificUrlQuery') + ->with('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1')) + ->will($this->returnValue($searchResult)); + + $retriever = new RewritingRetriever(); + + $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery'); + $rewritingUrlQuery->setValue($retriever, $retrieverQuery); + + $retriever->loadSpecificUrl('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1')); + + $this->assertEquals('foo.html', $retriever->rewrittenUrl); + $this->assertEquals(URL::viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url); } } diff --git a/core/lib/Thelia/Tools/I18n.php b/core/lib/Thelia/Tools/I18n.php new file mode 100644 index 000000000..82a17506d --- /dev/null +++ b/core/lib/Thelia/Tools/I18n.php @@ -0,0 +1,16 @@ + + */ + +namespace Thelia\Tools; + + +class I18n +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index b84fdca73..a527746ce 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -25,18 +25,33 @@ namespace Thelia\Tools; use Symfony\Component\HttpFoundation\Request; use Thelia\Model\ConfigQuery; +use Thelia\Rewriting\RewritingResolver; use Thelia\Rewriting\RewritingRetriever; class URL { + protected $resolver = null; + protected $retriever = null; + const PATH_TO_FILE = true; const WITH_INDEX_PAGE = false; + public function __construct() + { + $this->retriever = new RewritingRetriever(); + $this->resolver = new RewritingResolver(); + } + public static function getIndexPage() { return ConfigQuery::read('base_url', '/') . "index_dev.php"; // FIXME ! } + public static function init() + { + return new 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 @@ -103,7 +118,7 @@ class URL */ public static function viewUrl($viewName, array $parameters = array()) { - $path = sprintf("%s?view=%s", self::getIndexPage(), $viewName); + $path = sprintf("?view=%s", $viewName); return self::absoluteUrl($path, $parameters); } @@ -115,18 +130,17 @@ class URL * * @return null|string */ - public static function retrieve($view, $viewId, $viewLocale) + public function retrieve($view, $viewId, $viewLocale) { $rewrittenUrl = null; if(ConfigQuery::isRewritingEnable()) { - $retriever = new RewritingRetriever(); - $rewrittenUrl = $retriever->getViewUrl($view, $viewLocale, $viewId); + $rewrittenUrl = $this->retriever->loadViewUrl($view, $viewLocale, $viewId); } return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; } - public static function retrieveCurrent(Request $request) + public function retrieveCurrent(Request $request) { $rewrittenUrl = null; if(ConfigQuery::isRewritingEnable()) { @@ -134,12 +148,10 @@ class URL $viewLocale = $request->query->get('locale', null); $viewId = $view === null ? null : $request->query->get($view . '_id', null); - $allParameters = $request->query->all(); - $allParametersWithoutView = $allParameters; + $allOtherParameters = $request->query->all(); if($view !== null) { - unset($allParametersWithoutView['view']); + unset($allOtherParameters['view']); } - $allOtherParameters = $allParametersWithoutView; if($viewLocale !== null) { unset($allOtherParameters['locale']); } @@ -147,10 +159,15 @@ class URL unset($allOtherParameters[$view . '_id']); } - $retriever = new RewritingRetriever(); - $rewrittenUrl = $retriever->getSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters); + $this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters); } - return $rewrittenUrl === null ? self::viewUrl($view, $allParametersWithoutView) : $rewrittenUrl; + return $this->retriever; + } + + public function resolve($url) + { + $this->resolver->load($url); + return $this->resolver; } } diff --git a/documentation/api/classes/Thelia.Core.Event.TheliaEvents.html b/documentation/api/classes/Thelia.Core.Event.TheliaEvents.html index 3491e4264..fe9f532a1 100755 --- a/documentation/api/classes/Thelia.Core.Event.TheliaEvents.html +++ b/documentation/api/classes/Thelia.Core.Event.TheliaEvents.html @@ -1637,12 +1637,12 @@ AFTER_CREATECATEGORY
BEFORE_DELETECATEGORY
AFTER_DELETECATEGORY
- AFTER_CHANGECATEGORY
+ AFTER_UPDATECATEGORY
CART_DUPLICATE
AFTER_CARTADDITEM
- AFTER_CARTCHANGEITEM
+ AFTER_CARTUPDATEITEM
CART_ADDITEM
- CART_CHANGEITEM
+ CART_UPDATEITEM
CART_DELETEITEM
@@ -2023,8 +2023,8 @@
-

AFTER_CHANGECATEGORY

-
AFTER_CHANGECATEGORY
+

AFTER_UPDATECATEGORY

+
AFTER_UPDATECATEGORY

Sent just after a successful change of a category in the database.

@@ -2089,8 +2089,8 @@
-

AFTER_CARTCHANGEITEM

-
AFTER_CARTCHANGEITEM
+

AFTER_CARTUPDATEITEM

+
AFTER_CARTUPDATEITEM

sent when a cart item is modify

@@ -2133,8 +2133,8 @@
-

CART_CHANGEITEM

-
CART_CHANGEITEM
+

CART_UPDATEITEM

+
CART_UPDATEITEM

sent on modify article action

diff --git a/documentation/api/files/Action/Category.php.txt b/documentation/api/files/Action/Category.php.txt index a47d51c75..b62357b08 100755 --- a/documentation/api/files/Action/Category.php.txt +++ b/documentation/api/files/Action/Category.php.txt @@ -227,7 +227,7 @@ class Category extends BaseAction implements EventSubscriberInterface $categoryEvent = new CategoryEvent($category); - $event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECATEGORY, $categoryEvent); + $event->getDispatcher()->dispatch(TheliaEvents::AFTER_UPDATECATEGORY, $categoryEvent); } } diff --git a/documentation/api/files/Controller/Front/CartController.php.txt b/documentation/api/files/Controller/Front/CartController.php.txt index c800070e2..de27c7be4 100755 --- a/documentation/api/files/Controller/Front/CartController.php.txt +++ b/documentation/api/files/Controller/Front/CartController.php.txt @@ -74,7 +74,7 @@ class CartController extends BaseFrontController $cartEvent->setQuantity($this->getRequest()->get("quantity")); try { - $this->getDispatcher()->dispatch(TheliaEvents::CART_CHANGEITEM, $cartEvent); + $this->getDispatcher()->dispatch(TheliaEvents::CART_UPDATEITEM, $cartEvent); $this->redirectSuccess(); } catch(PropelException $e) { diff --git a/documentation/api/files/Core/Event/TheliaEvents.php.txt b/documentation/api/files/Core/Event/TheliaEvents.php.txt index 7ddc0b786..e06abc3c7 100755 --- a/documentation/api/files/Core/Event/TheliaEvents.php.txt +++ b/documentation/api/files/Core/Event/TheliaEvents.php.txt @@ -106,7 +106,7 @@ final class TheliaEvents /** * Sent just after a successful change of a category in the database. */ - const AFTER_CHANGECATEGORY = "action.after_changecategory"; + const AFTER_UPDATECATEGORY = "action.after_changecategory"; /** * sent when a new existing cat id duplicated. This append when current customer is different from current cart @@ -121,7 +121,7 @@ final class TheliaEvents /** * sent when a cart item is modify */ - const AFTER_CARTCHANGEITEM = "cart.modifyItem"; + const AFTER_CARTUPDATEITEM = "cart.modifyItem"; /** * sent for addArticle action @@ -131,7 +131,7 @@ final class TheliaEvents /** * sent on modify article action */ - const CART_CHANGEITEM = "action.changeArticle"; + const CART_UPDATEITEM = "action.changeArticle"; const CART_DELETEITEM = "action.deleteArticle"; } diff --git a/documentation/api/files/Model/CartItem.php.txt b/documentation/api/files/Model/CartItem.php.txt index a9671b57b..d956fd25d 100755 --- a/documentation/api/files/Model/CartItem.php.txt +++ b/documentation/api/files/Model/CartItem.php.txt @@ -32,7 +32,7 @@ class CartItem extends BaseCartItem if ($this->dispatcher) { $cartEvent = new CartEvent($this->getCart()); - $this->dispatcher->dispatch(TheliaEvents::AFTER_CARTCHANGEITEM, $cartEvent); + $this->dispatcher->dispatch(TheliaEvents::AFTER_CARTUPDATEITEM, $cartEvent); } } diff --git a/install/insert.sql b/install/insert.sql index 41c63e353..a4b7d3c1b 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -6,14 +6,16 @@ INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`created_at`, INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES ('session_config.default', '1', 1, 1, NOW(), NOW()), -('verifyStock', '1', 1, 0, NOW(), NOW()), -('default_lang_without_translation', '1', 1, 0, NOW(), NOW()), -('rewriting_enable', '0', 1, 0, NOW(), NOW()), -('imagine_graphic_driver', 'gd', 1, 0, NOW(), NOW()), -('default_images_quality_percent', '75', 1, 0, NOW(), NOW()), -('original_image_delivery_mode', 'symlink', 1, 0, NOW(), NOW()), -('images_library_path', 'local/media/images', 1, 0, NOW(), NOW()), -('image_cache_dir_from_web_root', 'cache/images', 1, 0, NOW(), NOW()); +('verifyStock', '1', 0, 0, NOW(), NOW()), +('default_lang_without_translation', '1', 0, 0, NOW(), NOW()), +('rewriting_enable', '0', 0, 0, NOW(), NOW()), +('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()), +('default_images_quality_percent', '75', 0, 0, NOW(), NOW()), +('original_image_delivery_mode', 'symlink', 0, 0, NOW(), NOW()), +('images_library_path', 'local/media/images', 0, 0, NOW(), NOW()), +('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()), +('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()), +('page_not_found_view', '404.html', 0, 0, NOW(), NOW()); INSERT INTO `module` (`code`, `type`, `activate`, `position`, `created_at`, `updated_at`) VALUES ('test', '1', '1', '1', NOW(), NOW()); @@ -38,12 +40,12 @@ VALUES INSERT INTO `currency_i18n` (`id` ,`locale` ,`name`) VALUES -(1, 'fr_FR', 'euro'), -(1, 'en_UK', 'euro'), -(2, 'fr_FR', 'dollar'), -(2, 'en_UK', 'dollar'), -(3, 'fr_FR', 'livre'), -(3, 'en_UK', 'pound'); +(1, 'fr_FR', 'Euro'), +(1, 'en_UK', 'Euro'), +(2, 'fr_FR', 'Dollar Américain'), +(2, 'en_UK', 'United States Dollar'), +(3, 'fr_FR', 'Livre anglaise'), +(3, 'en_UK', 'UK Pound'); INSERT INTO `country` (`id`, `area_id`, `isocode`, `isoalpha2`, `isoalpha3`, `created_at`, `updated_at`) VALUES diff --git a/install/thelia.sql b/install/thelia.sql index 9ba021507..85c00b369 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -455,7 +455,7 @@ DROP TABLE IF EXISTS `address`; CREATE TABLE `address` ( `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255), + `label` VARCHAR(255), `customer_id` INTEGER NOT NULL, `title_id` INTEGER NOT NULL, `company` VARCHAR(255), diff --git a/local/config/schema.xml b/local/config/schema.xml index 062e5088a..ea2b108fb 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,1130 +1,1130 @@ - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - -
- - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
- - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - -
-
\ No newline at end of file + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ diff --git a/reset_install.sh b/reset_install.sh index 8a3fe0c75..38a698afa 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -15,14 +15,11 @@ echo -e "\n\e[01;34m[INFO] Building Models file\e[00m\n" echo -e "\n\e[01;34m[INFO] Building SQL CREATE file\e[00m\n" ../../bin/propel sql:build -v --output-dir=../../install/ -# Not working : insert manually -# echo -e "\n\e[01;34m[INFO] Inserting SQL\e[00m\n" -# ../../bin/propel insert-sql -v --output-dir=../../install/ -# install/thelia.sql -# install/insert.sql -echo -e "\n\e[01;34m[INFO] Reinstalling Thelia2\e[00m\n" -cd ../.. -php Thelia thelia:install --db_host localhost --db_username thelia2 --db_password thelia2 --db_name thelia2 + + echo -e "\n\e[01;34m[INFO] Reloaded Thelia2 database\e[00m\n" + cd ../.. + rm install/sqldb.map + php Thelia thelia:dev:reloadDB echo -e "\n\e[01;34m[INFO] Installing fixtures\e[00m\n" php install/faker.php diff --git a/templates/admin/default/assets/css/admin.less b/templates/admin/default/assets/css/admin.less index a342d6528..961784425 100755 --- a/templates/admin/default/assets/css/admin.less +++ b/templates/admin/default/assets/css/admin.less @@ -666,6 +666,7 @@ form .info .input-append .add-on { li.active a { opacity: 1; background-color: #E7E7E7; + border: 1px solid #E9720F; } } } @@ -702,6 +703,7 @@ label { font-weight: normal; } + .form-horizontal input + .help-block, .form-horizontal select + .help-block, .form-horizontal textarea + .help-block, @@ -709,9 +711,10 @@ label { .form-horizontal .input-prepend + .help-block, .form-horizontal .input-append + .help-block .help-block, .form-horizontal .help-block { - margin-top: 0px; + margin-top: 5px; } + // Fix for append-fields shorter than others // see http://stackoverflow.com/questions/13306670/bootstrap-prepended-and-appended-input-how-to-max-input-field-width .input-append.input-block-level, @@ -770,6 +773,17 @@ label { td, th { text-align: center; + + &.text-center { + text-align: center; + } + &.text-left { + text-align: left; + } + &.text-right { + text-align: right; + } + } td.object-title, th.object-title { diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index ef08145e6..1450cf88a 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -47,54 +47,40 @@   + - {if $category_order == 'alpha'} - - {$order_change = 'alpha_reverse'} - {elseif $category_order == 'alpha_reverse'} - - {$order_change = 'alpha'} - {else} - {$order_change = 'alpha'} - {/if} - - {intl l="Category title"} - - + {admin_sortable_header + 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'} + } + {module_include location='category_list_header'} - {if $category_order == 'visible'} - - {$order_change = 'visible_reverse'} - {elseif $category_order == 'visible_reverse'} - - {$order_change = 'visible'} - {else} - {$order_change = 'visible'} - {/if} - - - {intl l="Online"} - + {admin_sortable_header + current_order=$category_order + order='visible' + reverse_order='visible_reverse' + path={url path='/admin/catalog/category' id="{$current_category_id}"} + label={intl l='Online'} + } - {if $category_order == 'manual'} - - {$order_change = 'manual_reverse'} - {elseif $category_order == 'manual_reverse'} - - {$order_change = 'manual'} - {else} - {$order_change = 'manual'} - {/if} - - {intl l="Position"} + {admin_sortable_header + current_order=$category_order + order='manual' + reverse_order='manual_reverse' + path={url path='/admin/catalog/category' id="{$current_category_id}"} + label={intl l='Position'} + } - {intl l="Actions"} +   @@ -126,15 +112,14 @@ - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"} - - {$POSITION} - - {/loop} - - {elseloop rel="can_change"} - {$POSITION} - {/elseloop} + {admin_position_block + permission="admin.category.edit" + path={url path='admin/catalog/category' category_id="{$ID}"} + url_parameter="category_id" + in_place_edit_class="categoryPositionChange" + position="$POSITION" + id="$ID" + } @@ -200,13 +185,38 @@   - {intl l="Product title"} + + {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'} + } {module_include location='product_list_header'} - {intl l="Online"} - {intl l="Position"} - {intl l="Actions"} + + {admin_sortable_header + current_order=$product_order + order='visible' + reverse_order='visible_reverse' + path={url path='/admin/catalog/product' id="{$current_category_id}"} + label={intl l='Online'} + } + + + + {admin_sortable_header + current_order=$product_order + order='manual' + reverse_order='manual_reverse' + path={url path='/admin/catalog/product' id="{$current_category_id}"} + label={intl l='Position'} + } + + +   @@ -229,13 +239,18 @@ - - {$POSITION} - + {admin_position_block + permission="admin.product.edit" + path={url path='admin/catalog/product' category_id="{$ID}"} + url_parameter="product_id" + in_place_edit_class="productPositionChange" + position="$POSITION" + id="$ID" + } - + diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index f93ae236f..b715cd741 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -6,6 +6,10 @@ {form_hidden_fields form=$form} + {form_field form=$form field='locale'} + + {/form_field} +
diff --git a/templates/admin/default/currencies.html b/templates/admin/default/currencies.html index 762bb47ee..a693214d7 100644 --- a/templates/admin/default/currencies.html +++ b/templates/admin/default/currencies.html @@ -26,7 +26,7 @@
-
+
- - - - - + {module_include location='currencies_table_header'} @@ -136,37 +118,37 @@ {loop name="currencies" type="currency" backend_context="1" lang=$lang_id order=$order} + - + - + - + - + - + - - - + {module_include location='currencies_table_row'} @@ -228,7 +210,7 @@ - - - + + + + + {module_include location='variables_table_header'} - {loop name="config" type="config" hidden="0" secured="*" backend_context="1" lang="$lang_id"} + {loop name="config" type="config" hidden="0" secured="*" backend_context="1" lang="$lang_id" order="$order"} @@ -172,6 +198,10 @@
{loop type="lang" name="default-lang" default_only="1"} + + {* Switch edition to the current locale *} + + {form_field form=$form field='locale'} {/form_field} diff --git a/templates/default/404.html b/templates/default/404.html new file mode 100644 index 000000000..7e2e925b4 --- /dev/null +++ b/templates/default/404.html @@ -0,0 +1,3 @@ +

PAGE NOT FOUND

+ +Back Home \ No newline at end of file diff --git a/templates/install/index.html b/templates/install/index.html new file mode 100644 index 000000000..a996cc241 --- /dev/null +++ b/templates/install/index.html @@ -0,0 +1,12 @@ +{extends file="layout.html"} +{block name="content"} +

{intl l="Thelia installation wizard"}

+
+ + {intl l="Bienvenue au sein du programme d'installation de Thelia."}
+ {intl l="Nous allons vous guider tout au long de ce processus afin d'installer l'application sur votre système."}

+ +
+ + +{/block} \ No newline at end of file diff --git a/templates/install/layout.html b/templates/install/layout.html new file mode 100644 index 000000000..0a13586ad --- /dev/null +++ b/templates/install/layout.html @@ -0,0 +1,49 @@ + + + + {block name="title"}Thelia Install{/block} + + {images file='../admin/default/assets/img/favicon.ico'}{/images} + + + + {stylesheets file='../admin/default/assets/bootstrap/css/bootstrap.css' filters='cssembed'} + + {/stylesheets} + + {stylesheets file='../admin/default/assets/bootstrap/css/bootstrap-responsive.css' filters='cssembed'} + + {/stylesheets} + + + {stylesheets file='../admin/default/assets/css/*' filters='less,cssembed'} + + {/stylesheets} + + + +
+
+
{intl l='Version %ver' ver="{$THELIA_VERSION}"}
+
+
+
+ {block name="content"}{/block} +
+ +
+ + + + \ No newline at end of file
@@ -35,99 +35,81 @@ + {/loop}
- {if $order == 'id'} - - {$order_change = 'id_reverse'} - {elseif $order == 'id_reverse'} - - {$order_change = 'id'} - {else} - {$order_change = 'id'} - {/if} - - {intl l="ID"} - + {admin_sortable_header + current_order=$order + order='id' + reverse_order='id_reverse' + path='/admin/configuration/currencies' + label="{intl l='ID'}" + } - {if $order == 'alpha'} - - {$order_change = 'alpha_reverse'} - {elseif $order == 'alpha_reverse'} - - {$order_change = 'alpha'} - {else} - {$order_change = 'alpha'} - {/if} - - {intl l="Name"} - + {admin_sortable_header + current_order=$order + order='alpha' + reverse_order='alpha_reverse' + path='/admin/configuration/currencies' + label="{intl l='Name'}" + } - {if $order == 'code'} - - {$order_change = 'code_reverse'} - {elseif $order == 'code_reverse'} - - {$order_change = 'code'} - {else} - {$order_change = 'code'} - {/if} - {intl l="ISO 4217 Code"} + + {admin_sortable_header + current_order=$order + order='code' + reverse_order='code_reverse' + path='/admin/configuration/currencies' + label="{intl l="ISO 4217 Code"}" + } - {if $order == 'symbol'} - - {$order_change = 'symbol_reverse'} - {elseif $order == 'symbol_reverse'} - - {$order_change = 'symbol'} - {else} - {$order_change = 'symbol'} - {/if} - - {intl l="Symbol"} - + + {admin_sortable_header + current_order=$order + order='symbol' + reverse_order='symbol_reverse' + path='/admin/configuration/currencies' + label="{intl l="Symbol"}" + } - {if $order == 'rate'} - - {$order_change = 'rate_reverse'} - {elseif $order == 'rate_reverse'} - - {$order_change = 'rate'} - {else} - {$order_change = 'rate'} - {/if} - - {intl l="Rate in €"} - + + {admin_sortable_header + current_order=$order + order='rate' + reverse_order='rate_reverse' + path='/admin/configuration/currencies' + label="{intl l="Rate in €"}" + } - {if $order == 'manual'} - - {$order_change = 'manual_reverse'} - {elseif $order == 'manual_reverse'} - - {$order_change = 'manual'} - {else} - {$order_change = 'manual'} - {/if} - - {intl l="Position"} + + {admin_sortable_header + current_order=$order + order='manual' + reverse_order='manual_reverse' + path='/admin/configuration/currencies' + label="{intl l="Position"}" + } {intl l="Default"} + {admin_sortable_header + current_order=$order + order='is_default' + reverse_order='is_default_reverse' + path='/admin/configuration/currencies' + label="{intl l="Default"}" + } +
{$ID}{$ID} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.currencies.change"} + {$NAME} + {/loop} + {elseloop rel="can_change"} + {$NAME} + {/elseloop} + - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.currencies.change"} - {$NAME} - {/loop} - {elseloop rel="can_change"} - {$NAME} - {/elseloop} - {$ISOCODE}{$ISOCODE}{$SYMBOL}{$SYMBOL}{format_number number="$RATE" decimals="4"}{$RATE|string_format:"%.4f"} + {admin_position_block + permission="admin.currencies.edit" + path="/admin/configuration/currencies" + url_parameter="currency_id" + in_place_edit_class="currencyPositionChange" + position="$POSITION" + id="$ID" + } + - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"} - - {$POSITION} - - {/loop} - - {elseloop rel="can_change"} - {$POSITION} - {/elseloop} - + +
{intl l="Purpose"}{intl l="Name"}{intl l="Value"} + {admin_sortable_header + current_order=$order + order='title' + reverse_order='title_reverse' + path={url path='/admin/configuration/variables'} + label={intl l='Purpose'} + } + + {admin_sortable_header + current_order=$order + order='name' + reverse_order='name_reverse' + path={url path='/admin/configuration/variables'} + label={intl l='Name'} + } + + {admin_sortable_header + current_order=$order + order='value' + reverse_order='value_reverse' + path={url path='/admin/configuration/variables'} + label={intl l='Value'} + } +  
{$TITLE}