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

# By Etienne Roudeix
# Via Etienne Roudeix
* 'master' of https://github.com/thelia/thelia:
  load test
  url output in loops
  backend loop translation
  backend trasnlation in loops
This commit is contained in:
gmorel
2013-08-28 15:46:56 +02:00
26 changed files with 641 additions and 319 deletions

View File

@@ -15,6 +15,7 @@
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
<loop class="Thelia\Core\Template\Loop\Content" name="content"/>
<loop class="Thelia\Core\Template\Loop\Country" name="country"/>
<loop class="Thelia\Core\Template\Loop\Currency" name="currency"/>
<loop class="Thelia\Core\Template\Loop\Customer" name="customer"/>
<loop class="Thelia\Core\Template\Loop\Feature" name="feature"/>
<loop class="Thelia\Core\Template\Loop\FeatureAvailability" name="feature_availability"/>

View File

@@ -80,6 +80,7 @@ abstract class BaseLoop
Argument::createIntTypeArgument('offset', 0),
Argument::createIntTypeArgument('page'),
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
Argument::createBooleanTypeArgument('backend_context', false),
);
}

View File

@@ -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,12 @@ class Attribute extends BaseLoop
{
$search = AttributeQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -151,6 +157,7 @@ class Attribute extends BaseLoop
foreach ($attributes as $attribute) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $attribute->getId())
->set("IS_TRANSLATED",$attribute->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$attribute->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $attribute->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $attribute->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -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(
@@ -78,8 +79,12 @@ class AttributeAvailability extends BaseLoop
{
$search = AttributeAvQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -126,6 +131,7 @@ class AttributeAvailability extends BaseLoop
foreach ($attributesAv as $attributeAv) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $attributeAv->getId())
->set("IS_TRANSLATED",$attributeAv->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$attributeAv->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $attributeAv->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $attributeAv->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -79,7 +79,7 @@ class AttributeCombination extends BaseLoop
$search = AttributeCombinationQuery::create();
/* manage attribute translations */
ModelCriteriaTools::getI18n(
ModelCriteriaTools::getFrontEndI18n(
$search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),
@@ -89,7 +89,7 @@ class AttributeCombination extends BaseLoop
);
/* manage attributeAv translations */
ModelCriteriaTools::getI18n(
ModelCriteriaTools::getFrontEndI18n(
$search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),

View File

@@ -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(
@@ -97,8 +98,12 @@ class Category extends BaseLoop
{
$search = CategoryQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -174,6 +179,7 @@ class Category extends BaseLoop
$loopResultRow
->set("ID", $category->getId())
->set("IS_TRANSLATED",$category->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$category->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -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(
@@ -87,8 +88,12 @@ class Content extends BaseLoop
{
$search = ContentQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -215,11 +220,13 @@ class Content extends BaseLoop
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $content->getId())
->set("IS_TRANSLATED",$content->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$content->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $content->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $content->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("POSITION", $content->getPosition())
->set("URL", $content->getUrl())
;
$loopResult->addRow($loopResultRow);

View File

@@ -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')
);
}
@@ -69,8 +70,12 @@ class Country extends BaseLoop
{
$search = CountryQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -108,6 +113,7 @@ class Country extends BaseLoop
foreach ($countries as $country) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $country->getId())
->set("IS_TRANSLATED",$country->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$country->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -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')
);
}
@@ -68,8 +69,12 @@ class Currency extends BaseLoop
{
$search = CurrencyQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME'));
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME'));
$id = $this->getId();
@@ -99,8 +104,10 @@ class Currency extends BaseLoop
foreach ($currencies as $currency) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $currency->getId())
->set("IS_TRANSLATED",$currency->getVirtualColumn('IS_TRANSLATED'))
->set("NAME",$currency->getVirtualColumn('i18n_NAME'))
->set("ISOCODE", $currency->getCode())
->set("SYMBOL", $currency->getSymbol())
->set("RATE", $currency->getRate())
->set("IS_DEFAULT", $currency->getByDefault());

View File

@@ -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(
@@ -83,8 +84,12 @@ class Feature extends BaseLoop
{
$search = FeatureQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -149,6 +154,7 @@ class Feature extends BaseLoop
foreach ($features as $feature) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $feature->getId())
->set("IS_TRANSLATED",$feature->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$feature->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $feature->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $feature->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -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(
@@ -76,8 +77,12 @@ class FeatureAvailability extends BaseLoop
{
$search = FeatureAvQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -124,6 +129,7 @@ class FeatureAvailability extends BaseLoop
foreach ($featuresAv as $featureAv) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $featureAv->getId())
->set("IS_TRANSLATED",$featureAv->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$featureAv->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $featureAv->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $featureAv->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -84,7 +84,7 @@ class FeatureValue extends BaseLoop
$search = FeatureProductQuery::create();
/* manage featureAv translations */
ModelCriteriaTools::getI18n(
ModelCriteriaTools::getFrontEndI18n(
$search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),

View File

@@ -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(
@@ -79,8 +80,12 @@ class Folder extends BaseLoop
{
$search = FolderQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -157,11 +162,13 @@ class Folder extends BaseLoop
$loopResultRow
->set("ID", $folder->getId())
->set("IS_TRANSLATED",$folder->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$folder->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT", $folder->getParent())
->set("URL", $folder->getUrl())
->set("CONTENT_COUNT", $folder->countChild())
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
->set("POSITION", $folder->getPosition())

View File

@@ -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(
@@ -137,8 +138,12 @@ class Product extends BaseLoop
{
$search = ProductQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$attributeNonStrictMatch = $this->getAttribute_non_strict_match();
$isPSELeftJoinList = array();
@@ -510,10 +515,12 @@ class Product extends BaseLoop
$loopResultRow->set("ID", $product->getId())
->set("REF",$product->getRef())
->set("IS_TRANSLATED",$product->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("URL", $product->getUrl())
->set("BEST_PRICE", $product->getVirtualColumn('real_lowest_price'))
->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo'))
->set("IS_NEW", $product->getVirtualColumn('main_product_is_new'))

View File

@@ -53,7 +53,8 @@ class Title extends BaseLoop
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id')
Argument::createIntListTypeArgument('id'),
Argument::createIntTypeArgument('lang')
);
}
@@ -66,8 +67,12 @@ class Title extends BaseLoop
{
$search = CustomerTitleQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
$id = $this->getId();
@@ -85,6 +90,7 @@ class Title extends BaseLoop
foreach ($titles as $title) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $title->getId())
->set("IS_TRANSLATED",$title->getVirtualColumn('IS_TRANSLATED'))
->set("DEFAULT", $title->getByDefault())
->set("SHORT", $title->getVirtualColumn('i18n_SHORT'))
->set("LONG", $title->getVirtualColumn('i18n_LONG'));

View File

@@ -5,7 +5,8 @@ namespace Thelia\Model;
use Thelia\Model\Base\Category as BaseCategory;
use Propel\Runtime\ActiveQuery\Criteria;
class Category extends BaseCategory {
class Category extends BaseCategory
{
/**
* @return int number of child for the current category
*/

View File

@@ -4,6 +4,10 @@ namespace Thelia\Model;
use Thelia\Model\Base\Content as BaseContent;
class Content extends BaseContent {
class Content extends BaseContent
{
public function getUrl()
{
}
}

View File

@@ -14,6 +14,11 @@ class Folder extends BaseFolder
return FolderQuery::countChild($this->getId());
}
public function getUrl()
{
}
/**
*
* count all products for current category and sub categories

View File

@@ -5,5 +5,10 @@ namespace Thelia\Model;
use Thelia\Model\Base\Product as BaseProduct;
use Thelia\Model\ProductSaleElements;
class Product extends BaseProduct {
class Product extends BaseProduct
{
public function getUrl()
{
}
}

View File

@@ -23,7 +23,7 @@ class ModelCriteriaTools
* @param null $foreignTable
* @param string $foreignKey
*/
public static function getI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
public static function getFrontEndI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
@@ -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 . 'IS_TRANSLATED');
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 . 'IS_TRANSLATED');
$search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
foreach($columns as $column) {
@@ -70,4 +74,45 @@ 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 . 'IS_TRANSLATED');
foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
}
public static function getI18n($backendContext, $lang, ModelCriteria &$search, $defaultLangWithoutTranslation, $currentLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($lang !== null) {
$localeSearch = LangQuery::create()->findOneById($lang);
if($localeSearch === null) {
throw new \InvalidArgumentException('Incorrect lang argument given in attribute loop');
}
}
if($backendContext) {
self::getBackEndI18n($search, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey);
} else {
self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey);
}
}
}

View File

@@ -0,0 +1,173 @@
<?php
use Thelia\Model\ProductImage;
use Thelia\Model\CategoryImage;
use Thelia\Model\FolderImage;
use Thelia\Model\ContentImage;
use Imagine\Image\Color;
use Imagine\Image\Point;
require __DIR__ . '/../core/bootstrap.php';
$thelia = new Thelia\Core\Thelia("dev", true);
$faker = Faker\Factory::create();
$con = \Propel\Runtime\Propel::getConnection(Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
$con->beginTransaction();
$currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne();
try {
$stmt = $con->prepare("SET foreign_key_checks = 0");
$stmt->execute();
$productAssociatedContent = Thelia\Model\ProductAssociatedContentQuery::create()
->find();
$productAssociatedContent->delete();
$categoryAssociatedContent = Thelia\Model\CategoryAssociatedContentQuery::create()
->find();
$categoryAssociatedContent->delete();
$attributeCategory = Thelia\Model\AttributeCategoryQuery::create()
->find();
$attributeCategory->delete();
$featureCategory = Thelia\Model\FeatureCategoryQuery::create()
->find();
$featureCategory->delete();
$featureProduct = Thelia\Model\FeatureProductQuery::create()
->find();
$featureProduct->delete();
$attributeCombination = Thelia\Model\AttributeCombinationQuery::create()
->find();
$attributeCombination->delete();
$feature = Thelia\Model\FeatureQuery::create()
->find();
$feature->delete();
$feature = Thelia\Model\FeatureI18nQuery::create()
->find();
$feature->delete();
$featureAv = Thelia\Model\FeatureAvQuery::create()
->find();
$featureAv->delete();
$featureAv = Thelia\Model\FeatureAvI18nQuery::create()
->find();
$featureAv->delete();
$attribute = Thelia\Model\AttributeQuery::create()
->find();
$attribute->delete();
$attribute = Thelia\Model\AttributeI18nQuery::create()
->find();
$attribute->delete();
$attributeAv = Thelia\Model\AttributeAvQuery::create()
->find();
$attributeAv->delete();
$attributeAv = Thelia\Model\AttributeAvI18nQuery::create()
->find();
$attributeAv->delete();
$category = Thelia\Model\CategoryQuery::create()
->find();
$category->delete();
$category = Thelia\Model\CategoryI18nQuery::create()
->find();
$category->delete();
$product = Thelia\Model\ProductQuery::create()
->find();
$product->delete();
$product = Thelia\Model\ProductI18nQuery::create()
->find();
$product->delete();
$customer = Thelia\Model\CustomerQuery::create()
->find();
$customer->delete();
$folder = Thelia\Model\FolderQuery::create()
->find();
$folder->delete();
$folder = Thelia\Model\FolderI18nQuery::create()
->find();
$folder->delete();
$content = Thelia\Model\ContentQuery::create()
->find();
$content->delete();
$content = Thelia\Model\ContentI18nQuery::create()
->find();
$content->delete();
$accessory = Thelia\Model\AccessoryQuery::create()
->find();
$accessory->delete();
$stock = \Thelia\Model\ProductSaleElementsQuery::create()
->find();
$stock->delete();
$productPrice = \Thelia\Model\ProductPriceQuery::create()
->find();
$productPrice->delete();
$stmt = $con->prepare("SET foreign_key_checks = 1");
$stmt->execute();
//categories and products
for($i=0; $i<100; $i++) {
$category = new Thelia\Model\Category();
$category->setParent(0);
$category->setVisible(1);
$category->setPosition($i);
setI18n($faker, $category);
$category->save();
for($j=0; $j<10; $j++) {
$product = new Thelia\Model\Product();
$product->setRef($category->getId() . '_' . $j . '_' . $faker->randomNumber(8));
$product->addCategory($category);
$product->setVisible(1);
$product->setPosition($j);
setI18n($faker, $product);
$product->save();
}
}
$con->commit();
} catch (Exception $e) {
echo "error : ".$e->getMessage()."\n";
$con->rollBack();
}
function setI18n($faker, &$object)
{
$localeList = array('fr_FR', 'en_EN', 'es_ES', 'it_IT');
$title = $faker->text(20);
$description = $faker->text(50);
foreach($localeList as $locale) {
$object->setLocale($locale);
$object->setTitle($locale . ' : ' . $title);
$object->setDescription($locale . ' : ' . $description);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -221,4 +221,16 @@
{/loop}
</ul>
<hr />
<h2>CURRENCIES</h2>
<ul>
{loop name="cur" type="currency"}
<li>
#NAME (#SYMBOL)
</li>
{/loop}
</ul>
</div>

View File

@@ -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" lang="2" backend_context="true"}
<li>
{if #IS_TRANSLATED == 1}#TITLE{else}to be translated{/if}
<ul>
{loop name="attrav" type="attribute_availability" order="manual" attribute="#ID" lang="3"}
<li>{if #IS_TRANSLATED == 1}#TITLE{else}to be translated{/if}</li>
{/loop}
</ul>
</li>
{/loop}
</ul>

11
templates/default/tester.html Executable file
View File

@@ -0,0 +1,11 @@
<ul>
{loop name="car" type="category"}
<li>
<ul>
{loop name="product" type="product" category="#ID"}
<li>#REF</li>
{/loop}
</ul>
</li>
{/loop}
</ul>

View File

@@ -51,3 +51,4 @@ $response = $thelia->handle($request)->prepare($request)->send();
$thelia->terminate($request, $response);
echo "\n<!-- page parsed in : " . (microtime(true) - $thelia->getStartTime())." s. -->";
echo "\n<!-- memory peak : " . memory_get_peak_usage()/1024/1024 . " MiB. -->";