Merge branch 'loops'
Conflicts: core/lib/Thelia/Config/Resources/config.xml
This commit is contained in:
@@ -45,8 +45,9 @@ abstract class BaseLoop
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @var Thelia\Core\Security\SecurityContext
|
||||
* @var SecurityContext
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
@@ -56,9 +57,9 @@ abstract class BaseLoop
|
||||
/**
|
||||
* Create a new Loop
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||
* @param Thelia\Core\Security\SecurityContext $securityContext
|
||||
* @param Request $request
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
* @param SecurityContext $securityContext
|
||||
*/
|
||||
public function __construct(Request $request, EventDispatcherInterface $dispatcher, SecurityContext $securityContext)
|
||||
{
|
||||
@@ -66,20 +67,20 @@ abstract class BaseLoop
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->securityContext = $securityContext;
|
||||
|
||||
$this->args = $this->getArgDefinitions()->addArguments($this->getDefaultArgs());
|
||||
$this->args = $this->getArgDefinitions()->addArguments($this->getDefaultArgs(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define common loop arguments
|
||||
*
|
||||
* @return an array ofL \Thelia\Core\Template\Loop\Argument\Argument
|
||||
* @return Argument[]
|
||||
*/
|
||||
protected function getDefaultArgs()
|
||||
{
|
||||
return array(
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', 10),
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', 10),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,7 +88,9 @@ abstract class BaseLoop
|
||||
* Provides a getter to loop parameters
|
||||
*
|
||||
* @param string $name the methode name (only getArgname is supported)
|
||||
* @param mixed $arguments this parameter is ignored
|
||||
* @param $arguments this parameter is ignored
|
||||
*
|
||||
* @return null
|
||||
* @throws \InvalidArgumentException if the parameter is unknown or the method name is not supported.
|
||||
*/
|
||||
public function __call($name, $arguments) {
|
||||
|
||||
@@ -115,9 +115,6 @@ class Address extends BaseLoop
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($addresses as $address) {
|
||||
|
||||
if ($this->not_empty && $address->countAllProducts() == 0) continue;
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $address->getId());
|
||||
$loopResultRow->set("NAME", $address->getName());
|
||||
|
||||
@@ -34,7 +34,7 @@ class ArgumentCollection implements \Iterator
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addArguments(func_get_args());
|
||||
$this->addArguments(func_get_args(), true);
|
||||
}
|
||||
|
||||
public function hasKey($key) {
|
||||
@@ -51,14 +51,15 @@ class ArgumentCollection implements \Iterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $argumentList
|
||||
* @param array $argumentList
|
||||
* @param $force
|
||||
*
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
public function addArguments(array $argumentList)
|
||||
public function addArguments(array $argumentList, $force = true)
|
||||
{
|
||||
foreach($argumentList as $argument) {
|
||||
$this->addArgument($argument);
|
||||
$this->addArgument($argument, $force);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -66,11 +67,16 @@ class ArgumentCollection implements \Iterator
|
||||
|
||||
/**
|
||||
* @param Argument $argument
|
||||
* @param $force
|
||||
*
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
public function addArgument(Argument $argument)
|
||||
public function addArgument(Argument $argument, $force = true)
|
||||
{
|
||||
if(isset($this->arguments[$argument->name]) && ! $force) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->arguments[$argument->name] = $argument;
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -32,7 +32,7 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\CustomerCountryQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
@@ -54,7 +54,11 @@ class Country extends BaseLoop
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id')
|
||||
Argument::createIntTypeArgument('limit', 500), // overwrite orginal param to increase the limit
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('area'),
|
||||
Argument::createBooleanTypeArgument('with_area'),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ class Country extends BaseLoop
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = CustomerCountryQuery::create();
|
||||
$search = CountryQuery::create();
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
@@ -73,6 +77,26 @@ class Country extends BaseLoop
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$area = $this->getArea();
|
||||
|
||||
if (null !== $area) {
|
||||
$search->filterByAreaId($area, Criteria::IN);
|
||||
}
|
||||
|
||||
$withArea = $this->getWith_area();
|
||||
|
||||
if (true === $withArea) {
|
||||
$search->filterByAreaId(null, Criteria::ISNOTNULL);
|
||||
} elseif (false == $withArea) {
|
||||
$search->filterByAreaId(null, Criteria::ISNULL);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (!is_null($exclude)) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
@@ -84,21 +108,23 @@ class Country extends BaseLoop
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);
|
||||
|
||||
$search->orderByPosition();
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CountryI18nTableMap::TITLE);
|
||||
|
||||
$countrys = $this->search($search, $pagination);
|
||||
$countries = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($countrys as $country) {
|
||||
|
||||
if ($this->not_empty && $country->countAllProducts() == 0) continue;
|
||||
|
||||
foreach ($countries as $country) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $country->getId());
|
||||
$loopResultRow->set("DEFAULT", $country->getByDefault());
|
||||
$loopResultRow->set("SHORT", $country->getShort());
|
||||
$loopResultRow->set("LONG", $country->getLong());
|
||||
$loopResultRow->set("AREA", $country->getAreaId());
|
||||
$loopResultRow->set("TITLE", $country->getTitle());
|
||||
$loopResultRow->set("CHAPO", $country->getChapo());
|
||||
$loopResultRow->set("DESCRIPTION", $country->getDescription());
|
||||
$loopResultRow->set("POSTSCRIPTUM", $country->getPostscriptum());
|
||||
$loopResultRow->set("ISOCODE", $country->getIsocode());
|
||||
$loopResultRow->set("ISOALPHA2", $country->getIsoalpha2());
|
||||
$loopResultRow->set("ISOALPHA3", $country->getIsoalpha3());
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -118,9 +118,6 @@ class Customer extends BaseLoop
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
|
||||
if ($this->not_empty && $customer->countAllProducts() == 0) continue;
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $customer->getId());
|
||||
$loopResultRow->set("REF", $customer->getRef());
|
||||
|
||||
168
core/lib/Thelia/Core/Template/Loop/Feature.php
Executable file
168
core/lib/Thelia/Core/Template/Loop/Feature.php
Executable file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\ActiveQuery\Join;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\CategoryQuery;
|
||||
use Thelia\Model\Base\ProductCategoryQuery;
|
||||
use Thelia\Model\Base\FeatureQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Map\ProductCategoryTableMap;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* Feature loop
|
||||
*
|
||||
*
|
||||
* Class Feature
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Feature extends BaseLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('product'),
|
||||
Argument::createIntListTypeArgument('category'),
|
||||
Argument::createBooleanTypeArgument('visible', 1),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
|
||||
),
|
||||
'manual'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = FeatureQuery::create();
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (null !== $id) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (null !== $exclude) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$visible = $this->getVisible();
|
||||
|
||||
$search->filterByVisible($visible);
|
||||
|
||||
$product = $this->getProduct();
|
||||
$category = $this->getCategory();
|
||||
|
||||
if(null !== $product) {
|
||||
$productCategories = ProductCategoryQuery::create()->select(array(ProductCategoryTableMap::CATEGORY_ID))->filterByProductId($product, Criteria::IN)->find()->getData();
|
||||
|
||||
if(null === $category) {
|
||||
$category = $productCategories;
|
||||
} else {
|
||||
$category = array_merge($category, $productCategories);
|
||||
}
|
||||
}
|
||||
|
||||
if(null !== $category) {
|
||||
$search->filterByCategory(
|
||||
CategoryQuery::create()->filterById($category)->find(),
|
||||
Criteria::IN
|
||||
);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
* @todo : verify here if we want results for row without translations.
|
||||
*/
|
||||
|
||||
$search->joinWithI18n(
|
||||
$this->request->getSession()->getLocale(),
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);
|
||||
|
||||
$features = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($features as $feature) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $feature->getId());
|
||||
$loopResultRow->set("TITLE",$feature->getTitle());
|
||||
$loopResultRow->set("CHAPO", $feature->getChapo());
|
||||
$loopResultRow->set("DESCRIPTION", $feature->getDescription());
|
||||
$loopResultRow->set("POSTSCRIPTUM", $feature->getPostscriptum());
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
145
core/lib/Thelia/Core/Template/Loop/FeatureAvailable.php
Executable file
145
core/lib/Thelia/Core/Template/Loop/FeatureAvailable.php
Executable file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\ActiveQuery\Join;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\FeatureAvQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*todo : to be finished
|
||||
* FeatureAvailable loop
|
||||
*
|
||||
*
|
||||
* Class FeatureAvailable
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class FeatureAvailable extends BaseLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('feature'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
|
||||
),
|
||||
'manual'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = FeatureAvQuery::create();
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (null !== $id) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (null !== $exclude) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$feature = $this->getFeature();
|
||||
|
||||
if(null !== $feature) {
|
||||
$search->filterByFeatureId($feature, Criteria::IN);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE);
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
* @todo : verify here if we want results for row without translations.
|
||||
*/
|
||||
|
||||
$search->joinWithI18n(
|
||||
$this->request->getSession()->getLocale(),
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);
|
||||
|
||||
$featuresAv = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($featuresAv as $featureAv) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $featureAv->getId());
|
||||
$loopResultRow->set("TITLE",$featureAv->getTitle());
|
||||
$loopResultRow->set("CHAPO", $featureAv->getChapo());
|
||||
$loopResultRow->set("DESCRIPTION", $featureAv->getDescription());
|
||||
$loopResultRow->set("POSTSCRIPTUM", $featureAv->getPostscriptum());
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
153
core/lib/Thelia/Core/Template/Loop/FeatureValue.php
Executable file
153
core/lib/Thelia/Core/Template/Loop/FeatureValue.php
Executable file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\ActiveQuery\Join;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\FeatureProductQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* FeatureValue loop
|
||||
*
|
||||
*
|
||||
* Class FeatureValue
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class FeatureValue extends BaseLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('feature', null, true),
|
||||
Argument::createIntTypeArgument('product', null, true),
|
||||
Argument::createIntListTypeArgument('feature_available'),
|
||||
Argument::createBooleanTypeArgument('exclude_feature_available', 0),
|
||||
Argument::createBooleanTypeArgument('exclude_default_values', 0),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
|
||||
),
|
||||
'manual'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = FeatureProductQuery::create();
|
||||
|
||||
$feature = $this->getFeature();
|
||||
|
||||
$search->filterByFeatureId($feature, Criteria::EQUAL);
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$search->filterByProductId($product, Criteria::EQUAL);
|
||||
|
||||
$featureAvailable = $this->geFeature_available();
|
||||
|
||||
if (null !== $featureAvailable) {
|
||||
$search->filterByFeatureAvId($featureAvailable, Criteria::IN);
|
||||
}
|
||||
|
||||
$excludeFeatureAvailable = $this->getExclude_feature_available();
|
||||
if($excludeFeatureAvailable == true) {
|
||||
$search->filterByFeatureAvId(null, Criteria::NULL);
|
||||
}
|
||||
|
||||
$excludeDefaultValues = $this->getExclude_default_values();
|
||||
if($excludeDefaultValues == true) {
|
||||
$search->filterByByDefault(null, Criteria::NULL);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE);
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
* @todo : verify here if we want results for row without translations.
|
||||
*/
|
||||
|
||||
/*$search->joinWithI18n(
|
||||
$this->request->getSession()->getLocale(),
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);*/
|
||||
|
||||
$featureValues = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($featureValues as $featureValue) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $featureValue->getId());
|
||||
/*$loopResultRow->set("TITLE",$featureValue->getTitle());
|
||||
$loopResultRow->set("CHAPO", $featureValue->getChapo());
|
||||
$loopResultRow->set("DESCRIPTION", $featureValue->getDescription());
|
||||
$loopResultRow->set("POSTSCRIPTUM", $featureValue->getPostscriptum());*/
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,11 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\FeatureProdQuery;
|
||||
use Thelia\Model\Base\FeatureProductQuery;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\FeatureAvQuery;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Model\Map\FeatureProdTableMap;
|
||||
use Thelia\Model\Map\FeatureProductTableMap;
|
||||
use Thelia\Model\Map\ProductTableMap;
|
||||
use Thelia\Model\ProductCategoryQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
@@ -70,13 +70,13 @@ class Product extends BaseLoop
|
||||
)
|
||||
),
|
||||
Argument::createIntListTypeArgument('category'),
|
||||
Argument::createBooleanTypeArgument('new'),
|
||||
Argument::createBooleanTypeArgument('promo'),
|
||||
Argument::createFloatTypeArgument('min_price'),
|
||||
Argument::createFloatTypeArgument('max_price'),
|
||||
Argument::createIntTypeArgument('min_stock'),
|
||||
Argument::createFloatTypeArgument('min_weight'),
|
||||
Argument::createFloatTypeArgument('max_weight'),
|
||||
//Argument::createBooleanTypeArgument('new'),
|
||||
//Argument::createBooleanTypeArgument('promo'),
|
||||
//Argument::createFloatTypeArgument('min_price'),
|
||||
//Argument::createFloatTypeArgument('max_price'),
|
||||
//Argument::createIntTypeArgument('min_stock'),
|
||||
//Argument::createFloatTypeArgument('min_weight'),
|
||||
//Argument::createFloatTypeArgument('max_weight'),
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('current_category'),
|
||||
Argument::createIntTypeArgument('depth', 1),
|
||||
@@ -84,7 +84,7 @@ class Product extends BaseLoop
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'min_price', 'max_price', 'manual', 'manual_reverse', 'ref', 'promo', 'new', 'random', 'given_id'))
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', /*'min_price', 'max_price',*/ 'manual', 'manual_reverse', 'ref', /*'promo', 'new',*/ 'random', 'given_id'))
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
@@ -114,7 +114,7 @@ class Product extends BaseLoop
|
||||
{
|
||||
$search = ProductQuery::create();
|
||||
|
||||
$search->withColumn('CASE WHEN ' . ProductTableMap::PROMO . '=1 THEN ' . ProductTableMap::PRICE2 . ' ELSE ' . ProductTableMap::PRICE . ' END', 'real_price');
|
||||
//$search->withColumn('CASE WHEN ' . ProductTableMap::PROMO . '=1 THEN ' . ProductTableMap::PRICE2 . ' ELSE ' . ProductTableMap::PRICE . ' END', 'real_price');
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
@@ -147,7 +147,7 @@ class Product extends BaseLoop
|
||||
);
|
||||
}
|
||||
|
||||
$new = $this->getNew();
|
||||
/*$new = $this->getNew();
|
||||
|
||||
if ($new === true) {
|
||||
$search->filterByNewness(1, Criteria::EQUAL);
|
||||
@@ -169,15 +169,15 @@ class Product extends BaseLoop
|
||||
$search->filterByQuantity($min_stock, Criteria::GREATER_EQUAL);
|
||||
}
|
||||
|
||||
$min_price = $this->getMin_price();
|
||||
$min_price = $this->getMin_price();*/
|
||||
|
||||
if(null !== $min_price) {
|
||||
//if(null !== $min_price) {
|
||||
/**
|
||||
* Following should work but does not :
|
||||
*
|
||||
* $search->filterBy('real_price', $max_price, Criteria::GREATER_EQUAL);
|
||||
*/
|
||||
$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
|
||||
/*$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
|
||||
->condition('not_in_promo', ProductTableMap::PROMO . Criteria::NOT_EQUAL . '1')
|
||||
->condition('min_price2', ProductTableMap::PRICE2 . Criteria::GREATER_EQUAL . '?', $min_price)
|
||||
->condition('min_price', ProductTableMap::PRICE . Criteria::GREATER_EQUAL . '?', $min_price)
|
||||
@@ -186,24 +186,24 @@ class Product extends BaseLoop
|
||||
->where(array('not_in_promo_min_price', 'in_promo_min_price'), Criteria::LOGICAL_OR);
|
||||
}
|
||||
|
||||
$max_price = $this->getMax_price();
|
||||
$max_price = $this->getMax_price();*/
|
||||
|
||||
if(null !== $max_price) {
|
||||
//if(null !== $max_price) {
|
||||
/**
|
||||
* Following should work but does not :
|
||||
*
|
||||
* $search->filterBy('real_price', $max_price, Criteria::LESS_EQUAL);
|
||||
*/
|
||||
$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
|
||||
/*$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
|
||||
->condition('not_in_promo', ProductTableMap::PROMO . Criteria::NOT_EQUAL . '1')
|
||||
->condition('max_price2', ProductTableMap::PRICE2 . Criteria::LESS_EQUAL . '?', $max_price)
|
||||
->condition('max_price', ProductTableMap::PRICE . Criteria::LESS_EQUAL . '?', $max_price)
|
||||
->combine(array('in_promo', 'max_price2'), Criteria::LOGICAL_AND, 'in_promo_max_price')
|
||||
->combine(array('not_in_promo', 'max_price'), Criteria::LOGICAL_AND, 'not_in_promo_max_price')
|
||||
->where(array('not_in_promo_max_price', 'in_promo_max_price'), Criteria::LOGICAL_OR);
|
||||
}
|
||||
}*/
|
||||
|
||||
$min_weight = $this->getMin_weight();
|
||||
/*$min_weight = $this->getMin_weight();
|
||||
|
||||
if(null !== $min_weight) {
|
||||
$search->filterByWeight($min_weight, Criteria::GREATER_EQUAL);
|
||||
@@ -213,7 +213,7 @@ class Product extends BaseLoop
|
||||
|
||||
if(null !== $max_weight) {
|
||||
$search->filterByWeight($max_weight, Criteria::LESS_EQUAL);
|
||||
}
|
||||
}*/
|
||||
|
||||
$current = $this->getCurrent();
|
||||
|
||||
@@ -264,12 +264,12 @@ class Product extends BaseLoop
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
||||
break;
|
||||
case "min_price":
|
||||
/*case "min_price":
|
||||
$search->orderBy('real_price', Criteria::ASC);
|
||||
break;
|
||||
case "max_price":
|
||||
$search->orderBy('real_price', Criteria::DESC);
|
||||
break;
|
||||
break;*/
|
||||
case "manual":
|
||||
if(null === $this->category || count($this->category) != 1)
|
||||
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
||||
@@ -283,12 +283,12 @@ class Product extends BaseLoop
|
||||
case "ref":
|
||||
$search->orderByRef(Criteria::ASC);
|
||||
break;
|
||||
case "promo":
|
||||
/*case "promo":
|
||||
$search->orderByPromo(Criteria::DESC);
|
||||
break;
|
||||
case "new":
|
||||
$search->orderByNewness(Criteria::DESC);
|
||||
break;
|
||||
break;*/
|
||||
case "given_id":
|
||||
if(null === $id)
|
||||
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
||||
@@ -328,7 +328,7 @@ class Product extends BaseLoop
|
||||
$featureAlias = 'fa_' . $feature;
|
||||
if($feature_av != '*')
|
||||
$featureAlias .= '_' . $feature_av;
|
||||
$search->joinFeatureProd($featureAlias, Criteria::LEFT_JOIN)
|
||||
$search->joinFeatureProduct($featureAlias, Criteria::LEFT_JOIN)
|
||||
->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT);
|
||||
if($feature_av != '*')
|
||||
$search->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_AV_ID = ?", $feature_av, null, \PDO::PARAM_INT);
|
||||
@@ -356,7 +356,7 @@ class Product extends BaseLoop
|
||||
$featureAlias = 'fv_' . $feature;
|
||||
if($feature_value != '*')
|
||||
$featureAlias .= '_' . $feature_value;
|
||||
$search->joinFeatureProd($featureAlias, Criteria::LEFT_JOIN)
|
||||
$search->joinFeatureProduct($featureAlias, Criteria::LEFT_JOIN)
|
||||
->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT);
|
||||
if($feature_value != '*')
|
||||
$search->addJoinCondition($featureAlias, "`$featureAlias`.BY_DEFAULT = ?", $feature_value, null, \PDO::PARAM_STR);
|
||||
@@ -401,11 +401,11 @@ class Product extends BaseLoop
|
||||
$loopResultRow->set("CHAPO", $product->getChapo());
|
||||
$loopResultRow->set("DESCRIPTION", $product->getDescription());
|
||||
$loopResultRow->set("POSTSCRIPTUM", $product->getPostscriptum());
|
||||
$loopResultRow->set("PRICE", $product->getPrice());
|
||||
$loopResultRow->set("PROMO_PRICE", $product->getPrice2());
|
||||
$loopResultRow->set("WEIGHT", $product->getWeight());
|
||||
$loopResultRow->set("PROMO", $product->getPromo());
|
||||
$loopResultRow->set("NEW", $product->getNewness());
|
||||
//$loopResultRow->set("PRICE", $product->getPrice());
|
||||
//$loopResultRow->set("PROMO_PRICE", $product->getPrice2());
|
||||
//$loopResultRow->set("WEIGHT", $product->getWeight());
|
||||
//$loopResultRow->set("PROMO", $product->getPromo());
|
||||
//$loopResultRow->set("NEW", $product->getNewness());
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -91,9 +91,6 @@ class Title extends BaseLoop
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($titles as $title) {
|
||||
|
||||
if ($this->not_empty && $title->countAllProducts() == 0) continue;
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow->set("ID", $title->getId());
|
||||
$loopResultRow->set("DEFAULT", $title->getByDefault());
|
||||
|
||||
Reference in New Issue
Block a user