Merge branch 'master' into tax

This commit is contained in:
Etienne Roudeix
2013-09-10 12:29:08 +02:00
171 changed files with 17862 additions and 196 deletions

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Security\User\UserInterface;
use Thelia\Exception\InvalidCartException;
use Thelia\Model\CartQuery;
use Thelia\Model\Cart;
use Thelia\Model\Currency;
use Thelia\Tools\URL;
use Thelia\Model\Lang;
@@ -44,9 +45,9 @@ class Session extends BaseSession
/**
* @return \Thelia\Model\Lang|null
*/
public function getLang()
public function getLang($forceDefault = true)
{
return $this->get("thelia.current.lang", Lang::getDefaultLanguage());
return $this->get("thelia.current.lang", $forceDefault ? Lang::getDefaultLanguage():null);
}
public function setLang(Lang $lang)
@@ -68,6 +69,16 @@ class Session extends BaseSession
return $this;
}
public function setCurrency(Currency $currency)
{
$this->set("thelia.current.currency", $currency);
}
public function getCurrency($forceDefault = true)
{
return $this->get("thelia.current.currency", $forceDefault ? Currency::getDefaultCurrency():null);
}
// -- Customer user --------------------------------------------------------
public function setCustomerUser(UserInterface $user)

View File

@@ -31,6 +31,7 @@ use Thelia\Core\Template\ParserContext;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\FolderQuery;
use Thelia\Model\Product;
use Thelia\Model\ProductQuery;
@@ -132,6 +133,35 @@ class DataAccessFunctions extends AbstractSmartyPlugin
}
}
/**
* currency global data
*
* @param $params
* @param $smarty
*/
public function currencyDataAccess($params, $smarty)
{
$currency = $this->request->getSession()->getCurrency();
if ($currency) {
$currencyQuery = CurrencyQuery::create()
->filterById($currency->getId());
return $this->dataAccessWithI18n("Currency", $params, $currencyQuery, array("NAME"));
}
}
/**
* Lang global data
*
* @param $params
* @param $smarty
*/
public function langDataAccess($params, $smarty)
{
return $this->dataAccess("Lang", $params, $this->request->getSession()->getLang());
}
/**
* @param $objectLabel
* @param $params
@@ -231,6 +261,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin
new SmartyPluginDescriptor('function', 'category', $this, 'categoryDataAccess'),
new SmartyPluginDescriptor('function', 'content', $this, 'contentDataAccess'),
new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'),
new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'),
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
);
}
}

View File

@@ -135,9 +135,26 @@ class TheliaHttpKernel extends HttpKernel
if ($lang) {
$request->getSession()
->setLang($lang)
->setLocale($lang->getLocale())
;
}
$request->getSession()->setCurrency($this->defineCurrency($request));
}
protected function defineCurrency(Request $request)
{
$currency = null;
if ($request->query->has("currency")) {
$currency = Model\CurrencyQuery::create()->findOneByCode($request->query->get("currency"));
} else {
$currency = $request->getSession()->getCurrency(false);
}
if(null === $currency) {
$currency = Model\Currency::getDefaultCurrency();
}
return $currency;
}
/**
@@ -153,7 +170,7 @@ class TheliaHttpKernel extends HttpKernel
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));
if (is_null($lang)) {
return;
return Model\Lang::getDefaultLanguage();
}
//if each lang had is own domain, we redirect the user to the good one.
@@ -175,7 +192,7 @@ class TheliaHttpKernel extends HttpKernel
}
//check if lang is not defined. If not we have to search the good one.
if (null === $request->getSession()->getLang()) {
if (null === $request->getSession()->getLang(false)) {
if (Model\ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
//find lang with domain
@@ -183,7 +200,7 @@ class TheliaHttpKernel extends HttpKernel
}
//find default lang
return Model\LangQuery::create()->findOneByByDefault(1);
return Model\Lang::getDefaultLanguage();
}
}

View File

@@ -20,7 +20,7 @@ class Translator extends BaseTranslator
* Return this class instance, only once instanciated.
*
* @throws \RuntimeException if the class has not been instanciated.
* @return Thelia\Core\Translation\Translator the instance.
* @return \Thelia\Core\Translation\Translator the instance.
*/
public static function getInstance() {
if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized.");