backend trasnlation in loops
This commit is contained in:
@@ -80,6 +80,7 @@ abstract class BaseLoop
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
|
||||
Argument::createIntTypeArgument('backend_context', false),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\LangQuery;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\CategoryQuery;
|
||||
@@ -66,6 +67,7 @@ class Attribute extends BaseLoop
|
||||
Argument::createIntListTypeArgument('category'),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
@@ -85,8 +87,18 @@ class Attribute extends BaseLoop
|
||||
{
|
||||
$search = AttributeQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
$x = LangQuery::create()->findOneById($lang);
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
if($backendContext) {
|
||||
ModelCriteriaTools::getBackEndI18n($search, $lang === null ? $this->request->getSession()->getLocale() : $x);
|
||||
} else {
|
||||
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
}
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ class AttributeAvailability extends BaseLoop
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('attribute'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -77,6 +77,7 @@ class Category extends BaseLoop
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('not_empty', 0),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -65,6 +65,7 @@ class Content extends BaseLoop
|
||||
Argument::createBooleanTypeArgument('current_folder'),
|
||||
Argument::createIntTypeArgument('depth', 1),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -56,7 +56,8 @@ class Country extends BaseLoop
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('area'),
|
||||
Argument::createBooleanTypeArgument('with_area'),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntTypeArgument('lang')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ class Currency extends BaseLoop
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createBooleanTypeArgument('default_only', false)
|
||||
Argument::createBooleanTypeArgument('default_only', false),
|
||||
Argument::createIntTypeArgument('lang')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ class Feature extends BaseLoop
|
||||
Argument::createIntListTypeArgument('category'),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -57,6 +57,7 @@ class FeatureAvailability extends BaseLoop
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('feature'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -59,6 +59,7 @@ class Folder extends BaseLoop
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('not_empty', 0),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -85,6 +85,7 @@ class Product extends BaseLoop
|
||||
Argument::createBooleanTypeArgument('current_category'),
|
||||
Argument::createIntTypeArgument('depth', 1),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
|
||||
@@ -53,7 +53,8 @@ class Title extends BaseLoop
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id')
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntTypeArgument('lang')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ class ModelCriteriaTools
|
||||
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
|
||||
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
|
||||
|
||||
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
|
||||
|
||||
foreach($columns as $column) {
|
||||
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
|
||||
}
|
||||
@@ -63,6 +65,8 @@ class ModelCriteriaTools
|
||||
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
|
||||
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
|
||||
|
||||
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
|
||||
|
||||
$search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
|
||||
|
||||
foreach($columns as $column) {
|
||||
@@ -70,4 +74,29 @@ class ModelCriteriaTools
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getBackEndI18n(ModelCriteria &$search, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
|
||||
{
|
||||
if($foreignTable === null) {
|
||||
$foreignTable = $search->getTableMap()->getName();
|
||||
$aliasPrefix = '';
|
||||
} else {
|
||||
$aliasPrefix = $foreignTable . '_';
|
||||
}
|
||||
|
||||
$askedLocaleI18nAlias = 'asked_locale_i18n';
|
||||
|
||||
$askedLocaleJoin = new Join();
|
||||
$askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias);
|
||||
$askedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
|
||||
|
||||
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
|
||||
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
|
||||
|
||||
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
|
||||
|
||||
foreach($columns as $column) {
|
||||
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
{*loop name="product" type="product" new="on" promo="on" min_stock="20" attribute_non_strict_match="min_stock,promo"}
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||
{/loop*}
|
||||
<h2>ALL ATTRIBUTES AND THEIR AVAILABILITY</h2>
|
||||
|
||||
{*loop name="product" type="product" min_weight="1000" max_weight="6000" attribute_non_strict_match="*"}
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||
{/loop*}
|
||||
|
||||
{*loop name="product" type="product" min_price="100" max_price="300" min_stock="4" min_weight="6000" max_weight="7000" attribute_non_strict_match="*" promo="on"}
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||
{/loop*}
|
||||
|
||||
{*loop name="product" type="product" promo="0" min_stock="4" order="promo,min_price"}
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
|
||||
{/loop*}
|
||||
|
||||
{*loop name="product" type="product" order="promo,min_price"}
|
||||
<h3>PRODUCT : #REF / #TITLE (#ID) / NEW : #NEW / PROMO : #PROMO / best price : #BEST_PRICE</h3>
|
||||
{/loop*}
|
||||
|
||||
{loop name="product" type="product"}
|
||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||
{/loop}
|
||||
<ul>
|
||||
{loop name="attr" type="attribute" order="manual"}
|
||||
<li>
|
||||
#TITLE
|
||||
<ul>
|
||||
{loop name="attrav" type="attribute_availability" order="manual" attribute="#ID"}
|
||||
<li>#TITLE</li>
|
||||
{/loop}
|
||||
</ul>
|
||||
</li>
|
||||
{/loop}
|
||||
</ul>
|
||||
Reference in New Issue
Block a user