translate product in car. Fix #416

This commit is contained in:
Manuel Raynaud
2014-05-30 17:07:55 +02:00
parent fe620a5a3b
commit d439197133
3 changed files with 29 additions and 5 deletions

View File

@@ -82,9 +82,9 @@ class Cart extends BaseLoop implements ArraySearchLoopInterface
public function parseResults(LoopResult $loopResult)
{
$taxCountry = $this->container->get('thelia.taxEngine')->getDeliveryCountry();
$locale = $this->request->getSession()->getLang()->getLocale();
foreach ($loopResult->getResultDataCollection() as $cartItem) {
$product = $cartItem->getProduct();
$product = $cartItem->getProduct(null, $locale);
$productSaleElement = $cartItem->getProductSaleElements();
$loopResultRow = new LoopResultRow();

View File

@@ -8,6 +8,7 @@ use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\CartItem as BaseCartItem;
use Thelia\Core\Event\Cart\CartEvent;
use Thelia\Model\ConfigQuery;
use Thelia\TaxEngine\Calculator;
class CartItem extends BaseCartItem
@@ -89,6 +90,23 @@ class CartItem extends BaseCartItem
return $this->getPromo() == 1 ? $this->getPromoPrice() : $this->getPrice();
}
public function getProduct(ConnectionInterface $con = null, $locale = null)
{
$product = parent::getProduct($con);
$translation = $product->getTranslation($locale);
if ($translation->isNew()) {
if (ConfigQuery::getDefaultLangWhenNoTranslationAvailable()) {
$locale = Lang::getDefaultLanguage()->getLocale();
}
}
$product->setLocale($locale);
return $product;
}
public function getRealTaxedPrice(Country $country)
{
return $this->getPromo() == 1 ? $this->getTaxedPromoPrice($country) : $this->getTaxedPrice($country);

View File

@@ -17,6 +17,9 @@ use Thelia\Model\Map\LangTableMap;
class Lang extends BaseLang
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
protected static $defaultLanguage;
/**
* Return the default language object, using a local variable to cache it.
*
@@ -24,10 +27,13 @@ class Lang extends BaseLang
*/
public static function getDefaultLanguage()
{
$default_lang = LangQuery::create()->findOneByByDefault(1);
if (null === self::$defaultLanguage) {
self::$defaultLanguage = LangQuery::create()->findOneByByDefault(1);
if ($default_lang == null) throw new \RuntimeException("No default language is defined. Please define one.");
return $default_lang;
if (self::$defaultLanguage == null) throw new \RuntimeException("No default language is defined. Please define one.");
}
return self::$defaultLanguage;
}
public function toggleDefault()