Merge branch 'master' of https://github.com/thelia/thelia into coupon

# By Manuel Raynaud (22) and others
# Via Manuel Raynaud (7) and others
* 'master' of https://github.com/thelia/thelia: (32 commits)
  refactor name for updating actions
  choose UPDATE word for name actions
  add update address action and create tests
  404 not found management
  Working Fix unset namespace
  modify travis script
  test rewriting exception
  Fixed minor bug in Currencies
  Finished currency edition
  Added route methods
  address action implementation
  hot fix
  rewriting
  add address create controller and event
  Added AdminUtilities Smarty plugin, optimized templates
  update customer model createOrUpdate method
  update address model
  fix redirect process in viewListener
  refactor reset_install script
  refactor install process, database management in dedicated class
  ...

Conflicts:
	local/config/schema.xml
	reset_install.sh
This commit is contained in:
gmorel
2013-09-04 15:42:38 +02:00
103 changed files with 4436 additions and 1827 deletions

View File

@@ -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

View File

@@ -0,0 +1,108 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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)
);
}
}

View File

@@ -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),

View File

@@ -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),
);
}

View File

@@ -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());
if ($couponToUpdate !== null) {
$couponToUpdate->setIsEnabled(0);
$event->getDispatcher()->dispatch(
TheliaEvents::BEFORE_DISABLE_COUPON, $event
$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()
);
$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),
);
}
}

View File

@@ -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,6 +135,29 @@ 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}
*/
@@ -113,8 +165,11 @@ class Currency extends BaseAction implements EventSubscriberInterface
{
return array(
TheliaEvents::CURRENCY_CREATE => array("create", 128),
TheliaEvents::CURRENCY_MODIFY => array("modify", 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),
);
}
}

View File

@@ -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),
);
}

View File

@@ -0,0 +1,84 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <eroudeix@openstudio.fr>
*/
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),
);
}
}

View File

@@ -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(
"",
"<info>Creating Thelia database, please wait</info>",
""
));
$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; $i<count($tab); $i++) {
$queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
$queryTemp = str_replace("|", ";", $queryTemp);
$query[] = $queryTemp;
}
return $query;
}
/**
* create database if not exists
*
* @param \PDO $connection
* @param $dbName
*/
protected function createDatabase(\PDO $connection, $dbName)
{
$connection->query(
sprintf(
"CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8",
$dbName
)
);
}
/**
* test database access
*

View File

@@ -0,0 +1,70 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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(
'',
'<info>starting reloaded database, please wait</info>'
));
$database->insertSql();
$output->writeln(array(
'',
'<info>Database reloaded with success</info>',
''
));
}
}

View File

@@ -47,6 +47,11 @@
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.pageNotFound" class="Thelia\Action\PageNotFound">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
</config>

View File

@@ -70,6 +70,7 @@
<command class="Thelia\Command\ModuleGenerateModelCommand"/>
<command class="Thelia\Command\ModuleGenerateSqlCommand"/>
<command class="Thelia\Command\CreateAdminUser"/>
<command class="Thelia\Command\ReloadDatabaseCommand"/>
</commands>
<services>
@@ -180,6 +181,12 @@
<argument type="service" id="thelia.parser.context"/>
</service>
<service id="smarty.plugin.adminUtilities" class="Thelia\Core\Template\Smarty\Plugins\AdminUtilities" scope="request">
<tag name="thelia.parser.register_plugin"/>
<argument type="service" id="thelia.securityContext" />
</service>
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
<argument type="service" id="event_dispatcher" />
<argument type="service" id="service_container" />

View File

@@ -56,6 +56,17 @@
<tag name="router.register" priority="0"/>
</service>
<service id="router.install" class="%router.class%">
<argument type="service" id="router.xmlLoader"/>
<argument>install.xml</argument>
<argument type="collection">
<argument key="cache_dir">%kernel.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument>
</argument>
<argument type="service" id="request.context"/>
<tag name="router.register" priority="-1"/>
</service>
<service id="router.front" class="%router.class%">
<argument type="service" id="router.xmlLoader"/>
<argument>front.xml</argument>

View File

@@ -130,6 +130,14 @@
<default key="_controller">Thelia\Controller\Admin\CurrencyController::saveChangeAction</default>
</route>
<route id="admin.configuration.currencies.set-default" path="/admin/configuration/currencies/set-default">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::setDefaultAction</default>
</route>
<route id="admin.configuration.currencies.update-rates" path="/admin/configuration/currencies/update-rates">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updateRatesAction</default>
</route>
<route id="admin.configuration.currencies.delete" path="/admin/configuration/currencies/delete">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::deleteAction</default>
</route>

View File

@@ -9,6 +9,7 @@
<default key="_view">index</default>
</route>
<!-- Customer routes -->
<route id="customer.create.process" path="/customer/create" methods="post">
<default key="_controller">Thelia\Controller\Front\CustomerController::createAction</default>
<default key="_view">connexion</default>
@@ -25,7 +26,15 @@
<route id="customer.logout.process" path="/customer/logout">
<default key="_controller">Thelia\Controller\Front\CustomerController::logoutAction</default>
</route>
<!-- end customer routes -->
<!-- customer address routes -->
<route id="customer.adress.create" path="/customer/address/create" >
<default key="_controller">Thelia\Controller\Front\CustomerAddressController::createAction</default>
</route>
<!-- end customer address routes -->
<!-- cart routes -->
<route id="cart.add.process" path="/cart/add">
<default key="_controller">Thelia\Controller\Front\CartController::addItem</default>
<default key="_view">cart</default>
@@ -40,4 +49,8 @@
<default key="_controller">Thelia\Controller\Front\CartController::changeItem</default>
<default key="_view">cart</default>
</route>
<route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">
<default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default>
</route>
</routes>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="home" path="/install" >
<default key="_controller">Thelia\Controller\Install\InstallController::index</default>
</route>
<route id="home" path="/install/step/2" >
<default key="_controller">Thelia\Controller\Install\InstallController::checkPermission</default>
</route>
</routes>

View File

@@ -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,12 +217,14 @@ 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());
// 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(),
@@ -212,13 +235,14 @@ class BaseAdminController extends BaseController
'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())
));
// Update the current edition language in session
$this->getSession()->setAdminEditionLangId($edition_language);
$this->getSession()->setAdminEditionLangId($edition_language->getId());
// Render the template.
try {

View File

@@ -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')
);

View File

@@ -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');
}
}

View File

@@ -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,6 +101,8 @@ 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');
}
}

View File

@@ -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

View File

@@ -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()

View File

@@ -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();
}
}

View File

@@ -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));
}
}

View File

@@ -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) {

View File

@@ -0,0 +1,96 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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
);
}
}

View File

@@ -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 <mraynaud@openstudio.fr>
*/
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));

View File

@@ -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')) {

View File

@@ -0,0 +1,81 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Install;
use Symfony\Component\HttpFoundation\Response;
use Thelia\Controller\BaseController;
/**
* Class BaseInstallController
* @package Thelia\Controller\Install
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Install;
use Thelia\Install\BaseInstall;
use Thelia\Install\CheckPermission;
/**
* Class InstallController
* @package Thelia\Controller\Install
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -0,0 +1,267 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -38,11 +38,8 @@ use Thelia\Model\Coupon;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
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

View File

@@ -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;
}
public function getIsDefault()
{
return $this->is_default;
}
public function setIsDefault($is_default)
{
$this->is_default = $is_default;
return $this;
}
}

View File

@@ -65,6 +65,8 @@ class CurrencyCreateEvent extends CurrencyEvent
public function setSymbol($symbol)
{
$this->symbol = $symbol;
return $this;
}
public function getCode()

View File

@@ -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,14 +278,14 @@ 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";
@@ -284,15 +293,20 @@ final class TheliaEvents
// -- Currencies management ---------------------------------------------
const CURRENCY_CREATE = "action.createCurrency";
const CURRENCY_MODIFY = "action.changeCurrency";
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";
}

View File

@@ -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()));
}
}

View File

@@ -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;
}
/**

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
$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,8 +164,12 @@ 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("VERSION" , $result->getVersion())
->set("VERSION_DATE" , $result->getVersionCreatedAt())
->set("VERSION_AUTHOR" , $result->getVersionCreatedBy())
;
$loopResult->addRow($loopResultRow);

View File

@@ -66,6 +66,7 @@ class Currency extends BaseI18nLoop
'code', 'code_reverse',
'symbol', 'symbol_reverse',
'rate', 'rate_reverse',
'is_default', 'is_default_reverse',
'manual', 'manual_reverse')
)
),
@@ -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);
}

View File

@@ -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);

View File

@@ -0,0 +1,144 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <franck@cqfdev.fr>
*/
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');
/*
<a href="{url path='/admin/configuration/currencies/positionUp' currency_id=$ID}"><i class="icon-arrow-up"></i></a>
<span class="currencyPositionChange" data-id="{$ID}">{$POSITION}</span>
<a href="{url path='/admin/configuration/currencies/positionDown' currency_id=$ID}"><i class="icon-arrow-down"></i></a>
*/
if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($permission))) {
return sprintf(
'<a href="%s"><i class="icon-arrow-up"></i></a><span class="%s" data-id="%s">%s</span><a href="%s"><i class="icon-arrow-down"></i></a>',
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('<i class="icon icon-chevron-%s"></i> ', $icon);
else
$output = '';
return sprintf('%s<a href="%s">%s</a>', $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'),
);
}
}

View File

@@ -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()

View File

@@ -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

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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);
}
}

View File

@@ -0,0 +1,132 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Class AddressForm
* @package Thelia\Form
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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";
}
}

View File

@@ -136,6 +136,15 @@ class CouponCreationForm extends BaseForm
new NotBlank()
)
)
)
->add(
'locale',
'hidden',
array(
'constraints' => array(
new NotBlank()
)
)
);
}

View File

@@ -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));
}
}

View File

@@ -34,7 +34,7 @@ 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)))))
;
}

View File

@@ -0,0 +1,46 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Install;
use Thelia\Install\Exception\AlreadyInstallException;
/**
* Class BaseInstall
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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();
}

View File

@@ -0,0 +1,78 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Install;
/**
* Class CheckPermission
* @package Thelia\Install
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}
}
}

View File

@@ -0,0 +1,103 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Install;
/**
* Class Database
* @package Thelia\Install
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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; $i<count($tab); $i++) {
$queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
$queryTemp = str_replace("|", ";", $queryTemp);
$query[] = $queryTemp;
}
return $query;
}
/**
* create database if not exists
*
* @param $dbName
*/
public function createDatabase($dbName)
{
$this->connection->query(
sprintf(
"CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8",
$dbName
)
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Install\Exception;
/**
* Class AlreadyInstallException
* @package Thelia\Install\Exception
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AlreadyInstallException extends InstallException
{
}

View File

@@ -0,0 +1,32 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Install\Exception;
/**
* Class InstallException
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class InstallException extends \RuntimeException
{
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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:
* <code>
* $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%'
* </code>
*
* @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);
}
/**

View File

@@ -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);
}
}

View File

@@ -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)

View File

@@ -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));
}
/**

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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()
}
/**

View File

@@ -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));
}
/**

View File

@@ -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,8 +75,7 @@ class Customer extends BaseCustomer implements UserInterface
$con = Propel::getWriteConnection(CustomerTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$this->save($con);
if ($this->isNew()) {
$address = new Address();
$address
@@ -90,12 +90,31 @@ class Customer extends BaseCustomer implements UserInterface
->setZipcode($zipcode)
->setCountryId($countryId)
->setIsDefault(1)
->setCustomer($this)
->save($con);
;
$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);
$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)
{

View File

@@ -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);
}
/**

View File

@@ -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');

View File

@@ -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));
}
/**

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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 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;
if(empty($viewOtherParameters)) {
$this->loadViewUrl($view, $viewLocale, $viewId);
return;
}
$urlQuery->where($parameterConditions, Criteria::LOGICAL_OR);
$this->search = $this->rewritingUrlQuery->getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters);
$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)');
$allParametersWithoutView = $viewOtherParameters;
$allParametersWithoutView['locale'] = $viewLocale;
if(null !== $viewId) {
$allParametersWithoutView[$view . '_id'] = $viewId;
}
$url = $urlQuery->findOne();
return $url === null ? null : $url->getUrl();
$this->url = URL::viewUrl($view, $allParametersWithoutView);
if($this->search !== null) {
$this->rewrittenUrl = $this->search->getUrl();
}
}
}

View File

@@ -0,0 +1,145 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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());
}
}

View File

@@ -0,0 +1,154 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Rewriting;
use Thelia\Model\RewritingArgument;
use Thelia\Rewriting\RewritingResolver;
use Propel\Runtime\Collection\ObjectCollection;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
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);
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Created by JetBrains PhpStorm.
* Date: 9/4/13
* Time: 2:55 PM
*
* @author Guillaume MOREL <gmorel@openstudio.fr>
*/
namespace Thelia\Tools;
class I18n
{
}

View File

@@ -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;
}
}

View File

@@ -1637,12 +1637,12 @@
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CREATECATEGORY" class="">AFTER_CREATECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_BEFORE_DELETECATEGORY" class="">BEFORE_DELETECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_DELETECATEGORY" class="">AFTER_DELETECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CHANGECATEGORY" class="">AFTER_CHANGECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CHANGECATEGORY" class="">AFTER_UPDATECATEGORY</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_CART_DUPLICATE" class="">CART_DUPLICATE</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CARTADDITEM" class="">AFTER_CARTADDITEM</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CARTCHANGEITEM" class="">AFTER_CARTCHANGEITEM</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_AFTER_CARTCHANGEITEM" class="">AFTER_CARTUPDATEITEM</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_CART_ADDITEM" class="">CART_ADDITEM</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_CART_CHANGEITEM" class="">CART_CHANGEITEM</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_CART_CHANGEITEM" class="">CART_UPDATEITEM</a><br />
<a href="../classes/Thelia.Core.Event.TheliaEvents.html#constant_CART_DELETEITEM" class="">CART_DELETEITEM</a><br />
</section>
</section>
@@ -2023,8 +2023,8 @@
<div class="span8 content class">
<a id="constant_AFTER_CHANGECATEGORY" name="constant_AFTER_CHANGECATEGORY" class="anchor"></a>
<article id="constant_AFTER_CHANGECATEGORY" class="constant">
<h3 class="">AFTER_CHANGECATEGORY</h3>
<pre class="signature">AFTER_CHANGECATEGORY</pre>
<h3 class="">AFTER_UPDATECATEGORY</h3>
<pre class="signature">AFTER_UPDATECATEGORY</pre>
<p><em>Sent just after a successful change of a category in the database.</em></p>
@@ -2089,8 +2089,8 @@
<div class="span8 content class">
<a id="constant_AFTER_CARTCHANGEITEM" name="constant_AFTER_CARTCHANGEITEM" class="anchor"></a>
<article id="constant_AFTER_CARTCHANGEITEM" class="constant">
<h3 class="">AFTER_CARTCHANGEITEM</h3>
<pre class="signature">AFTER_CARTCHANGEITEM</pre>
<h3 class="">AFTER_CARTUPDATEITEM</h3>
<pre class="signature">AFTER_CARTUPDATEITEM</pre>
<p><em>sent when a cart item is modify</em></p>
@@ -2133,8 +2133,8 @@
<div class="span8 content class">
<a id="constant_CART_CHANGEITEM" name="constant_CART_CHANGEITEM" class="anchor"></a>
<article id="constant_CART_CHANGEITEM" class="constant">
<h3 class="">CART_CHANGEITEM</h3>
<pre class="signature">CART_CHANGEITEM</pre>
<h3 class="">CART_UPDATEITEM</h3>
<pre class="signature">CART_UPDATEITEM</pre>
<p><em>sent on modify article action</em></p>

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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";
}

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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),

View File

@@ -337,7 +337,7 @@
</table>
<table name="address" namespace="Thelia\Model">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="name" size="255" type="VARCHAR" />
<column name="label" size="255" type="VARCHAR" />
<column name="customer_id" required="true" type="INTEGER" />
<column name="title_id" required="true" type="INTEGER" />
<column name="company" size="255" type="VARCHAR" />

View File

@@ -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

View File

@@ -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 {

View File

@@ -47,54 +47,40 @@
<thead>
<tr>
<th class="object-image">&nbsp;</th>
<th class="object-title">
{if $category_order == 'alpha'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'alpha_reverse'}
{elseif $category_order == 'alpha_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'alpha'}
{else}
{$order_change = 'alpha'}
{/if}
<a href="{url path='/admin/catalog/category' id="{$current_category_id}" category_order="$order_change"}">
{intl l="Category title"}
</a>
{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'}
}
</th>
{module_include location='category_list_header'}
<th>
{if $category_order == 'visible'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'visible_reverse'}
{elseif $category_order == 'visible_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'visible'}
{else}
{$order_change = 'visible'}
{/if}
<a href="{url path='admin/catalog/category' id="{$current_category_id}" category_order="$order_change"}">
{intl l="Online"}
</a>
{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'}
}
</th>
<th>
{if $category_order == 'manual'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'manual_reverse'}
{elseif $category_order == 'manual_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'manual'}
{else}
{$order_change = 'manual'}
{/if}
<a href="{url path='admin/catalog/category' id="{$current_category_id}" category_order="$order_change"}">{intl l="Position"}</a>
{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'}
}
</th>
<th>{intl l="Actions"}</th>
<th>&nbsp;</th>
</tr>
</thead>
@@ -126,15 +112,14 @@
</td>
<td>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"}
<a href="{url path='admin/catalog/category' category_id="{$ID}" action='positionUp'}"><i class="icon-arrow-up"></i></a>
<span class="categoryPositionChange" data-id="{$ID}">{$POSITION}</span>
<a href="{url path='admin/catalog/category' category_id="{$ID}" action='positionDown'}"><i class="icon-arrow-down"></i></a>
{/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"
}
</td>
<td>
@@ -200,13 +185,38 @@
<tr>
<th>&nbsp;</th>
<th class="object-title">{intl l="Product title"}</th>
<th class="object-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'}
<th>{intl l="Online"}</th>
<th>{intl l="Position"}</th>
<th>{intl l="Actions"}</th>
<th>
{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'}
}
</th>
<th>
{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'}
}
</th>
<th>&nbsp;</th>
</tr>
</thead>
@@ -229,13 +239,18 @@
</td>
<td>
<a href="{url path='admin/catalog/product' id="$ID" action='positionUn'}"><i class="icon-arrow-up"></i></a>
<span class="object_classement_editable" data-action="changeProductPosition" data-name="product_id" data-id="{$ID}">{$POSITION}</span>
<a href="{url path='admin/catalog/product' id="$ID" action='positionDown'}"><i class="icon-arrow-down"></i></a>
{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"
}
</td>
<td>
<a class="btn btn-mini" title="{intl l='Edit this category'}" href="{url path='admin/catalog/product' id="$ID" action='edit'}"><i class="icon-edit"></i></a>
<a class="btn btn-mini" title="{intl l='Edit this product'}" href="{url path='admin/catalog/product' id="$ID" action='edit'}"><i class="icon-edit"></i></a>
<a class="btn btn-mini product-delete" title="{intl l='Delete this product'}" href="{url path='admin/catalog/product' id="$ID" action='delete'}"><i class="icon-trash"></i></a>
</td>
</tr>

View File

@@ -6,6 +6,10 @@
{form_hidden_fields form=$form}
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{if $value}{$value}{else}{$edit_language_locale}{/if}" />
{/form_field}
<div class="span4">
<div class="control-group">
<label for="code">Code :</label>

View File

@@ -26,7 +26,7 @@
<div class="row-fluid">
<div class="span12">
<form action="{url path='/admin/configuration/currencies/change-values'}" method="post">
<form action="{url path='/admin/configuration/currencies/update-rates'}" method="post">
<div class="general-block-decorator">
<table class="table table-striped table-condensed table-left-aligned">
<caption>
@@ -35,99 +35,81 @@
<a class="btn btn-primary action-btn" title="{intl l='Add a new currency'}" href="#add_currency_dialog" data-toggle="modal">
<i class="icon-plus-sign icon-white"></i>
</a>
<button class="btn btn-info action-btn" title="{intl l='Update rates'}">{intl l='Update rates'} <i class="icon icon-white icon-globe"></i></button>
{/loop}
</caption>
<tr>
<th>
{if $order == 'id'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'id_reverse'}
{elseif $order == 'id_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'id'}
{else}
{$order_change = 'id'}
{/if}
<a href="{url path='/admin/configuration/currencies' order=$order_change}">
{intl l="ID"}
</a>
{admin_sortable_header
current_order=$order
order='id'
reverse_order='id_reverse'
path='/admin/configuration/currencies'
label="{intl l='ID'}"
}
</th>
<th>
{if $order == 'alpha'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'alpha_reverse'}
{elseif $order == 'alpha_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'alpha'}
{else}
{$order_change = 'alpha'}
{/if}
<a href="{url path='/admin/configuration/currencies' order=$order_change}">
{intl l="Name"}
</a>
{admin_sortable_header
current_order=$order
order='alpha'
reverse_order='alpha_reverse'
path='/admin/configuration/currencies'
label="{intl l='Name'}"
}
</th>
<th>
{if $order == 'code'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'code_reverse'}
{elseif $order == 'code_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'code'}
{else}
{$order_change = 'code'}
{/if}
<a href="{url path='/admin/configuration/currencies' order=$order_change}">{intl l="ISO 4217 Code"}</a>
<th class="text-center">
{admin_sortable_header
current_order=$order
order='code'
reverse_order='code_reverse'
path='/admin/configuration/currencies'
label="{intl l="ISO 4217 Code"}"
}
<a title="{intl l='More information about ISO 4217'}" href="http://fr.wikipedia.org/wiki/ISO_4217" target="_blank"><i class="icon icon-question-sign"></i></a>
</th>
<th>
{if $order == 'symbol'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'symbol_reverse'}
{elseif $order == 'symbol_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'symbol'}
{else}
{$order_change = 'symbol'}
{/if}
<a href="{url path='/admin/configuration/currencies' order=$order_change}">
{intl l="Symbol"}
</a>
<th class="text-center">
{admin_sortable_header
current_order=$order
order='symbol'
reverse_order='symbol_reverse'
path='/admin/configuration/currencies'
label="{intl l="Symbol"}"
}
</th>
<th>
{if $order == 'rate'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'rate_reverse'}
{elseif $order == 'rate_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'rate'}
{else}
{$order_change = 'rate'}
{/if}
<a href="{url path='/admin/configuration/currencies' order=$order_change}">
{intl l="Rate in &euro;"}
</a>
<th class="text-right">
{admin_sortable_header
current_order=$order
order='rate'
reverse_order='rate_reverse'
path='/admin/configuration/currencies'
label="{intl l="Rate in &euro;"}"
}
</th>
<th>
{if $order == 'manual'}
<i class="icon icon-chevron-up"></i>
{$order_change = 'manual_reverse'}
{elseif $order == 'manual_reverse'}
<i class="icon icon-chevron-down"></i>
{$order_change = 'manual'}
{else}
{$order_change = 'manual'}
{/if}
<a href="{url path='/admin/configuration/currencies' order="$order_change"}">{intl l="Position"}</a>
<th class="text-center">
{admin_sortable_header
current_order=$order
order='manual'
reverse_order='manual_reverse'
path='/admin/configuration/currencies'
label="{intl l="Position"}"
}
</th>
<th>{intl l="Default"}</th>
<th class="text-center">
{admin_sortable_header
current_order=$order
order='is_default'
reverse_order='is_default_reverse'
path='/admin/configuration/currencies'
label="{intl l="Default"}"
}
</th>
{module_include location='currencies_table_header'}
@@ -136,7 +118,6 @@
{loop name="currencies" type="currency" backend_context="1" lang=$lang_id order=$order}
<tr>
<td>{$ID}</td>
<td>
@@ -148,25 +129,26 @@
{/elseloop}
</td>
<td>{$ISOCODE}</td>
<td class="text-center">{$ISOCODE}</td>
<td>{$SYMBOL}</td>
<td class="text-center">{$SYMBOL}</td>
<td>{$RATE|string_format:"%.4f"}</td>
<td class="text-right">{format_number number="$RATE" decimals="4"}</td>
<td>
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"}
<a href="{url path='/admin/configuration/currencies/positionUp' currency_id=$ID}"><i class="icon-arrow-up"></i></a>
<span class="currencyPositionChange" data-id="{$ID}">{$POSITION}</span>
<a href="{url path='/admin/configuration/currencies/positionDown' currency_id=$ID}"><i class="icon-arrow-down"></i></a>
{/loop}
{elseloop rel="can_change"}
{$POSITION}
{/elseloop}
<td class="text-center">
{admin_position_block
permission="admin.currencies.edit"
path="/admin/configuration/currencies"
url_parameter="currency_id"
in_place_edit_class="currencyPositionChange"
position="$POSITION"
id="$ID"
}
</td>
<td><input type="radio" name="default[{$ID}]" value="1" {if $IS_DEFAULT}checked="checked"{/if}/></td>
<td class="text-center">
<input class="change-default" type="radio" name="is_default" value="{$ID}" {if $IS_DEFAULT}checked="checked"{/if}/>
</td>
{module_include location='currencies_table_row'}
@@ -228,7 +210,7 @@
<div class="modal-body">
{if #form_error}<div class="alert alert-block alert-error" id="add_currency_dialog_error">#form_error_currency</div>{/if}
{if $form_error}<div class="alert alert-block alert-error" id="add_currency_dialog_error">{$form_error_message}</div>{/if}
<div class="control-group">
@@ -238,6 +220,10 @@
<div class="controls">
{loop type="lang" name="default-lang" default_only="1"}
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}
@@ -262,7 +248,7 @@
</label>
<div class="controls">
{form_field form=$form field='symbol'}
{form_field form=$form field='code'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value}" title="{intl l='ISO 4217 code'}" placeholder="{intl l='Code'}">
</span>
@@ -294,11 +280,11 @@
</label>
<div class="controls">
{form_field form=$form field='symbol'}
{form_field form=$form field='rate'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value}" title="{intl l='Currency rate'}" placeholder="{intl l='Rate'}">
</span>
<div class="help-block">{intl l="Currency rate, in Euro"}</div>
<div class="help-block">{intl l="The rate from Euro (Price in Euro * rate = Price in this currency)"}</div>
{/form_field}
</div>
</div>
@@ -396,6 +382,18 @@
}
});
{* Change default status *}
$('.change-default').click(function(ev) {
var url = "{url path='/admin/configuration/currencies/set-default' currency_id='__ID__'}";
// Perform ID subtitutions
url = url.replace('__ID__', $(this).val());
// Reload the page
location.href = url;
});
});
</script>
{/block}

View File

@@ -0,0 +1,147 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Edit a currency'}{/block}
{block name="check-permissions"}admin.configuration.currencies.edit{/block}
{block name="main-content"}
<div class="currencies edit-currency">
<div id="wrapper" class="container">
{loop name="currency_edit" type="currency" id="$currency_id" backend_context="1" lang="$edit_language_id"}
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a> <span class="divider">/</span></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a> <span class="divider">/</span></li>
<li><a href="{url path='/admin/configuration/currencies'}">{intl l="Currencies"}</a> <span class="divider">/</span></li>
<li>{intl l='Editing currency "%name"' name="{$NAME}"}</li>
</ul>
<div class="row-fluid">
<div class="span12 general-block-decorator">
<div class="row-fluid">
<div class="span12 title title-without-tabs">
{intl l="Edit currency $NAME"}
</div>
<div class="form-container">
<div class="form-horizontal span12">
{form name="thelia.admin.currency.modification"}
<form method="POST" action="{url path='/admin/configuration/currencies/save-change'}" {form_enctype form=$form}>
<fieldset>
{* Be sure to get the currency ID, even if the form could not be validated *}
<input type="hidden" name="currency_id" value="{$currency_id}" />
{include file="includes/inner-form-toolbar.html"}
{form_hidden_fields form=$form}
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{url path='/admin/configuration/currencies'}" />
{/form_field}
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$edit_language_locale}" />
{/form_field}
{if $form_error}<div class="alert alert-block alert-error">{$form_error_message}</div>{/if}
<div class="row-fluid">
<div class="span6">
<div class="control-group">
<label class="control-label">
{intl l='Name *'}
</label>
<div class="controls">
{form_field form=$form field='name'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value|htmlspecialchars}" title="{intl l='Currency name'}" placeholder="{intl l='Currency name'}" class="input-medium">
</span>
{/form_field}
</div>
</div>
<div class="control-group">
<label class="control-label">
{intl l='ISO 4217 Code *'}
<span class="label-help-block"><a title="{intl l='More information about ISO 4217'}" href="http://fr.wikipedia.org/wiki/ISO_4217" target="_blank">List of ISO 4217 code</a></span>
</label>
<div class="controls">
{form_field form=$form field='code'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value|htmlspecialchars}" title="{intl l='Currency ISO 4217 Code'}" placeholder="{intl l='Code'}" class="input-mini">
</span>
{/form_field}
</div>
</div>
</div>
<div class="span6">
<div class="control-group">
<label class="control-label">
{intl l='Symbol *'}
<span class="label-help-block">The symbol, sur as $, £, &euro;...</span>
</label>
<div class="controls">
{form_field form=$form field='symbol'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value|htmlspecialchars}" title="{intl l='Currency symbol'}" placeholder="{intl l='Symbol'}" class="input-mini">
</span>
{/form_field}
</div>
</div>
<div class="control-group">
<label class="control-label">
{intl l='Rate from &euro; *'}
<span class="label-help-block">The rate from Euro</span>
</label>
<div class="controls">
{form_field form=$form field='rate'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value|htmlspecialchars}" title="{intl l='Rate from Euro'}" placeholder="{intl l='Rate'}" class="input-mini">
</span>
{/form_field}
<span class="help-block">Price in Euro x rate = Price in this currency</span>
</div>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<p>{intl l='Currency created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}</p>
</div>
</div>
</fieldset>
</form>
{/form}
</div>
</div>
</div>
</div>
</div>
{/loop}
{elseloop rel="currency_edit"}
<div class="row-fluid">
<div class="span12">
<div class="alert alert-error">
{intl l="Sorry, currency ID=$currency_id was not found."}
</div>
</div>
</div>
{/elseloop}
</div>
</div>
{/block}

View File

@@ -12,7 +12,7 @@
</ul>
<div class="row-fluid">
{loop name="category_edit" type="category" visible="*" id="{$current_category_id}" backend_context="1" lang="$edition_language"}
{loop name="category_edit" type="category" visible="*" id="{$current_category_id}" backend_context="1" lang="$edit_language_id"}
<div class="span12 general-block-decorator">
<div class="row-fluid">
<div class="span7 title">
@@ -123,7 +123,7 @@
<div class="control-group">
<lablel>&nbsp;</lablel>
<div class="controls">
<p>{intl l='Category created on %date_create. Last modification: %date_change' date_create=$CREATE_DATE->format($datetime_format) date_change=$UPDATE_DATE->format($datetime_format)}</p>
<p>{intl l='Category created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}}</p>
</div>
</div>
</div>

View File

@@ -11,8 +11,8 @@
<ul class="nav nav-pills">
{loop name="lang_list" type="lang" default_only={$default_only}}
<li {if $ID == $edition_language}class="active"{/if}>
<a href="{$current_url}&amp;edition_language={$ID}" title="{intl l="Edit information in %lng" lng=$TITLE}">
<li {if $ID == $edit_language_id}class="active"{/if}>
<a href="{$current_url}&amp;edit_language_id={$ID}" title="{intl l="Edit information in %lng" lng=$TITLE}">
<img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
</a>
</li>

View File

@@ -9,7 +9,7 @@
<div id="wrapper" class="container">
{loop name="message_edit" type="message" secured="*" id="$message_id" backend_context="1" lang="$edition_language"}
{loop name="message_edit" type="message" secured="*" id="$message_id" backend_context="1" lang="$edit_language_id"}
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a> <span class="divider">/</span></li>
@@ -47,7 +47,7 @@
{/form_field}
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$value|htmlspecialchars}" />
<input type="hidden" name="{$name}" value="{{$edit_language_locale}}" />
{/form_field}
{if #form_error}<div class="alert alert-block alert-error">#form_error_message</div>{/if}
@@ -144,7 +144,7 @@
<div class="control-group">
<div class="controls">
<p>{intl l='Message created on %date_create. Last modification: %date_change' df=$datetime_format date_create=$CREATE_DATE->format($datetime_format) date_change=$UPDATE_DATE->format($datetime_format)}</p>
<p>{intl l='Message created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}}</p>
</div>
</div>
</fieldset>

View File

@@ -151,6 +151,10 @@
<div class="controls">
{loop type="lang" name="default-lang" default_only="1"}
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}

View File

@@ -9,7 +9,7 @@
<div id="wrapper" class="container">
{loop name="config_edit" type="config" hidden="*" id="$variable_id" backend_context="1" lang="$edition_language"}
{loop name="config_edit" type="config" hidden="*" id="$variable_id" backend_context="1" lang="$edit_language_id"}
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a> <span class="divider">/</span></li>
@@ -53,7 +53,7 @@
{/form_field}
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$value|htmlspecialchars}" />
<input type="hidden" name="{$name}" value="{$edit_language_locale}" />
{/form_field}
{if #form_error}<div class="alert alert-block alert-error">#form_error_message</div>{/if}
@@ -108,7 +108,7 @@
<div class="control-group">
<div class="controls">
<p>{intl l='Variable created on %date_create. Last modification: %date_change' df=$datetime_format date_create=$CREATE_DATE->format($datetime_format) date_change=$UPDATE_DATE->format($datetime_format)}</p>
<p>{intl l='Variable created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}</p>
</div>
</div>

View File

@@ -34,16 +34,42 @@
</caption>
<tr>
<th>{intl l="Purpose"}</th>
<th>{intl l="Name"}</th>
<th>{intl l="Value"}</th>
<th>
{admin_sortable_header
current_order=$order
order='title'
reverse_order='title_reverse'
path={url path='/admin/configuration/variables'}
label={intl l='Purpose'}
}
</th>
<th>
{admin_sortable_header
current_order=$order
order='name'
reverse_order='name_reverse'
path={url path='/admin/configuration/variables'}
label={intl l='Name'}
}
</th>
<th>
{admin_sortable_header
current_order=$order
order='value'
reverse_order='value_reverse'
path={url path='/admin/configuration/variables'}
label={intl l='Value'}
}
</th>
{module_include location='variables_table_header'}
<th>&nbsp;</th>
</tr>
{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"}
<tr>
<td>{$TITLE}</td>
@@ -172,6 +198,10 @@
<div class="controls">
{loop type="lang" name="default-lang" default_only="1"}
{* Switch edition to the current locale *}
<input type="hidden" name="edit_language_id" value="{$ID}" />
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$LOCALE}" />
{/form_field}

Some files were not shown because too many files have changed in this diff Show More