defin currency at runtime
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,17 @@ class Currency extends BaseCurrency {
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
public static function getDefaultCurrency()
|
||||
{
|
||||
$currency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
|
||||
if (null === $currency) {
|
||||
throw new \RuntimeException("No default currency is defined. Please define one.");
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -79,14 +79,13 @@ URL: http://www.thelia.net
|
||||
<li><a href="address.html">New address</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#">Category 1</a></li>
|
||||
<li><a href="#">Category 2</a></li>
|
||||
<li><a href="#">Category 3</a></li>
|
||||
<li><a href="#">Category 4</a></li>
|
||||
{loop type="category" name="category.navigation" parent="0" limit="3"}
|
||||
<li><a href="{#URL}">{#TITLE}</a></li>
|
||||
{/loop}
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-cart navbar-right">
|
||||
<li><a href="register.html" class="register">Register!</a></li>
|
||||
<li><a href="login.html" class="login">Log In!</a></li>
|
||||
<li><a href="{url path="/register"}" class="register">{intl l="Register"}!</a></li>
|
||||
<li><a href="{url path="/login"}" class="login">{intl l="Log In!"}</a></li>
|
||||
<li class="dropdown">
|
||||
<a href="cart.html" class="dropdown-toggle cart" data-toggle="dropdown">
|
||||
Cart <span class="badge">2</span>
|
||||
@@ -130,11 +129,12 @@ URL: http://www.thelia.net
|
||||
</div>
|
||||
|
||||
<div class="currency-switch" aria-labelledby="currency-label">
|
||||
<span id="currency-label" class="dropdown-label">Currency:</span>
|
||||
<span id="currency-label" class="dropdown-label">{intl l="Currency"}:</span>
|
||||
<a class="current dropdown-toggle" data-toggle="dropdown" href="currency.html">USD</a>
|
||||
<ul class="select dropdown-menu">
|
||||
<li><a href="?cur=euro">€ - Euro</a></li>
|
||||
<li><a href="?cur=dollar">$ - Dollar</a></li>
|
||||
{loop type="currency" name="currency_available" }
|
||||
<li><a href="?cur=euro">{#SYMBOL} - {#NAME}</a></li>
|
||||
{/loop}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user