Aded feature_template and category_template position management
This commit is contained in:
@@ -400,6 +400,7 @@ final class TheliaEvents
|
||||
const AFTER_DELETECURRENCY = "action.after_deleteCurrency";
|
||||
|
||||
const CHANGE_DEFAULT_CURRENCY = 'action.changeDefaultCurrency';
|
||||
|
||||
// -- Product templates management -----------------------------------------
|
||||
|
||||
const TEMPLATE_CREATE = "action.createTemplate";
|
||||
@@ -412,6 +413,9 @@ final class TheliaEvents
|
||||
const TEMPLATE_ADD_FEATURE = "action.templateAddFeature";
|
||||
const TEMPLATE_DELETE_FEATURE = "action.templateDeleteFeature";
|
||||
|
||||
const TEMPLATE_CHANGE_FEATURE_POSITION = "action.templateChangeAttributePosition";
|
||||
const TEMPLATE_CHANGE_ATTRIBUTE_POSITION = "action.templateChangeFeaturePosition";
|
||||
|
||||
const BEFORE_CREATETEMPLATE = "action.before_createTemplate";
|
||||
const AFTER_CREATETEMPLATE = "action.after_createTemplate";
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ use Thelia\Type\BooleanOrBothType;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
use Thelia\Model\AttributeTemplateQuery;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Map\AttributeTemplateTableMap;
|
||||
/**
|
||||
*
|
||||
* Attribute loop
|
||||
@@ -106,6 +107,9 @@ class Attribute extends BaseI18nLoop
|
||||
|
||||
$product = $this->getProduct();
|
||||
$template = $this->getTemplate();
|
||||
$exclude_template = $this->getExcludeTemplate();
|
||||
|
||||
$use_attribute_pos = true;
|
||||
|
||||
if (null !== $product) {
|
||||
// Find the template assigned to the product.
|
||||
@@ -114,29 +118,37 @@ class Attribute extends BaseI18nLoop
|
||||
// Ignore if the product cannot be found.
|
||||
if ($productObj !== null)
|
||||
$template = $productObj->getTemplate();
|
||||
}
|
||||
|
||||
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
|
||||
if (null !== $template) {
|
||||
$search->filterById(
|
||||
AttributeTemplateQuery::create()->filterByTemplateId($template)->select('attribute_id')->find(),
|
||||
Criteria::IN
|
||||
);
|
||||
}
|
||||
|
||||
$exclude_template = $this->getExcludeTemplate();
|
||||
if (null !== $template) {
|
||||
|
||||
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
|
||||
if (null !== $exclude_template) {
|
||||
// Exclure tous les attribut qui sont attachés aux templates indiqués
|
||||
$search->filterById(
|
||||
AttributeTemplateQuery::create()->filterByTemplateId($exclude_template)->select('attribute_id')->find(),
|
||||
Criteria::NOT_IN
|
||||
);
|
||||
// Join with feature_template table to get position
|
||||
$search
|
||||
->withColumn(AttributeTemplateTableMap::POSITION, 'position')
|
||||
->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN)
|
||||
;
|
||||
|
||||
$use_attribute_pos = false;
|
||||
}
|
||||
else if (null !== $exclude_template) {
|
||||
|
||||
// Join with attribute_template table to get position
|
||||
$exclude_attributes = AttributeTemplateQuery::create()->filterByTemplateId($exclude_template)->select('attribute_id')->find();
|
||||
|
||||
$search
|
||||
->joinAttributeTemplate(null, Criteria::LEFT_JOIN)
|
||||
->withColumn(AttributeTemplateTableMap::POSITION, 'position')
|
||||
->filterById($exclude_attributes, Criteria::NOT_IN)
|
||||
;
|
||||
|
||||
$use_attribute_pos = false;
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
if ($template == null && ($order == "manual" || $order == "manual_reverse"))
|
||||
throw new \InvalidException(Translator::getInstance()->trans("Can't use manual or manual_reverse order without a 'template' or 'produst' parameter"));
|
||||
|
||||
foreach ($orders as $order) {
|
||||
switch ($order) {
|
||||
case "id":
|
||||
@@ -152,10 +164,16 @@ class Attribute extends BaseI18nLoop
|
||||
$search->addDescendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
if ($use_attribute_pos)
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
else
|
||||
$search->addAscendingOrderByColumn(AttributeTemplateTableMap::POSITION);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
if ($use_attribute_pos)
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
else
|
||||
$search->addDescendingOrderByColumn(AttributeTemplateTableMap::POSITION);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -174,7 +192,8 @@ class Attribute extends BaseI18nLoop
|
||||
->set("CHAPO", $attribute->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION", $attribute->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $attribute->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("POSITION", $attribute->getPosition());
|
||||
->set("POSITION", $use_attribute_pos ? $attribute->getPosition() : $attribute->getVirtualColumn('position'))
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\BooleanOrBothType;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
use Thelia\Model\Map\FeatureTemplateTableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -70,7 +72,7 @@ class Feature extends BaseI18nLoop
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse'))
|
||||
new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha-reverse', 'manual', 'manual_reverse'))
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
@@ -108,6 +110,9 @@ class Feature extends BaseI18nLoop
|
||||
|
||||
$product = $this->getProduct();
|
||||
$template = $this->getTemplate();
|
||||
$exclude_template = $this->getExcludeTemplate();
|
||||
|
||||
$use_feature_pos = true;
|
||||
|
||||
if (null !== $product) {
|
||||
// Find the template assigned to the product.
|
||||
@@ -116,31 +121,35 @@ class Feature extends BaseI18nLoop
|
||||
// Ignore if the product cannot be found.
|
||||
if ($productObj !== null)
|
||||
$template = $productObj->getTemplate();
|
||||
}
|
||||
|
||||
// If we have to filter by template, find all features assigned to this template, and filter by found IDs
|
||||
if (null !== $template) {
|
||||
$search->filterById(
|
||||
FeatureTemplateQuery::create()->filterByTemplateId($template)->select('feature_id')->find(),
|
||||
Criteria::IN
|
||||
);
|
||||
}
|
||||
|
||||
$exclude_template = $this->getExcludeTemplate();
|
||||
if (null !== $template) {
|
||||
|
||||
// Join with feature_template table to get position
|
||||
$search
|
||||
->withColumn(FeatureTemplateTableMap::POSITION, 'position')
|
||||
->filterByTemplate(TemplateQuery::create()->findById($template), Criteria::IN)
|
||||
;
|
||||
|
||||
$use_feature_pos = false;
|
||||
}
|
||||
|
||||
// If we have to filter by template, find all features assigned to this template, and filter by found IDs
|
||||
if (null !== $exclude_template) {
|
||||
// Exclure tous les attribut qui sont attachés aux templates indiqués
|
||||
$search->filterById(
|
||||
FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find(),
|
||||
Criteria::NOT_IN
|
||||
);
|
||||
$exclude_features = FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find();
|
||||
|
||||
$search
|
||||
->joinFeatureTemplate(null, Criteria::LEFT_JOIN)
|
||||
->withColumn(FeatureTemplateTableMap::POSITION, 'position')
|
||||
->filterById($exclude_features, Criteria::NOT_IN)
|
||||
;
|
||||
|
||||
$use_feature_pos = false;
|
||||
}
|
||||
|
||||
$title = $this->getTitle();
|
||||
|
||||
if (null !== $title) {
|
||||
//find all feture that match exactly this title and find with all locales.
|
||||
//find all feature that match exactly this title and find with all locales.
|
||||
$features = FeatureI18nQuery::create()
|
||||
->filterByTitle($title, Criteria::LIKE)
|
||||
->select('id')
|
||||
@@ -158,6 +167,12 @@ class Feature extends BaseI18nLoop
|
||||
|
||||
foreach ($orders as $order) {
|
||||
switch ($order) {
|
||||
case "id":
|
||||
$search->orderById(Criteria::ASC);
|
||||
break;
|
||||
case "id_reverse":
|
||||
$search->orderById(Criteria::DESC);
|
||||
break;
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
@@ -165,14 +180,22 @@ class Feature extends BaseI18nLoop
|
||||
$search->addDescendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
if ($use_feature_pos)
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
else
|
||||
$search->addAscendingOrderByColumn(FeatureTemplateTableMap::POSITION);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
if ($use_feature_pos)
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
else
|
||||
$search->addDescendingOrderByColumn(FeatureTemplateTableMap::POSITION);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* perform search */
|
||||
$features = $this->search($search, $pagination);
|
||||
|
||||
@@ -187,7 +210,8 @@ class Feature extends BaseI18nLoop
|
||||
->set("CHAPO", $feature->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION", $feature->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $feature->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("POSITION", $feature->getPosition());
|
||||
->set("POSITION", $use_feature_pos ? $feature->getPosition() : $feature->getVirtualColumn('position'))
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,9 @@ class UrlGenerator extends AbstractSmartyPlugin
|
||||
public function generateUrlFunction($params, &$smarty)
|
||||
{
|
||||
// the path to process
|
||||
$path = $this->getParam($params, 'path', null);
|
||||
$file = $this->getParam($params, 'file', null);
|
||||
$path = $this->getParam($params, 'path', null);
|
||||
$file = $this->getParam($params, 'file', null); // Do not invoke index.php in URL (get a static file in web space
|
||||
$noamp = $this->getParam($params, 'noamp', null); // Do not change & in &
|
||||
|
||||
if ($file !== null) {
|
||||
$path = $file;
|
||||
@@ -66,12 +67,11 @@ class UrlGenerator extends AbstractSmartyPlugin
|
||||
|
||||
$url = URL::getInstance()->absoluteUrl(
|
||||
$path,
|
||||
$this->getArgsFromParam($params, array('path', 'file', 'target')),
|
||||
$this->getArgsFromParam($params, array('noamp', 'path', 'file', 'target')),
|
||||
$mode
|
||||
);
|
||||
|
||||
// FIXME: potentially dangerous ?
|
||||
$url = str_replace('&', '&', $url);
|
||||
if ($noamp == null) $url = str_replace('&', '&', $url);
|
||||
|
||||
if ($target != null) $url .= '#'.$target;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user