accessory loop
product loop order fix
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||||
|
|
||||||
<loops>
|
<loops>
|
||||||
|
<loop class="Thelia\Core\Template\Loop\Accessory" name="accessory"/>
|
||||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||||
<loop class="Thelia\Core\Template\Loop\Product" name="product"/>
|
<loop class="Thelia\Core\Template\Loop\Product" name="product"/>
|
||||||
<loop class="Thelia\Core\Template\Loop\Feed" name="feed"/>
|
<loop class="Thelia\Core\Template\Loop\Feed" name="feed"/>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ abstract class BaseLoop
|
|||||||
protected $securityContext;
|
protected $securityContext;
|
||||||
|
|
||||||
|
|
||||||
private $args;
|
protected $args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Loop
|
* Create a new Loop
|
||||||
|
|||||||
119
core/lib/Thelia/Core/Template/Loop/Accessory.php
Executable file
119
core/lib/Thelia/Core/Template/Loop/Accessory.php
Executable file
@@ -0,0 +1,119 @@
|
|||||||
|
<?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 Thelia\Core\Template\Loop\Product;
|
||||||
|
|
||||||
|
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\AccessoryQuery;
|
||||||
|
use Thelia\Model\ProductQuery;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
|
use Thelia\Type\TypeCollection;
|
||||||
|
use Thelia\Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Accessory loop
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Class Accessory
|
||||||
|
* @package Thelia\Core\Template\Loop
|
||||||
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class Accessory extends Product
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return ArgumentCollection
|
||||||
|
*/
|
||||||
|
protected function getArgDefinitions()
|
||||||
|
{
|
||||||
|
$argumentCollection = parent::getArgDefinitions();
|
||||||
|
|
||||||
|
$argumentCollection->addArgument(
|
||||||
|
Argument::createIntListTypeArgument('product', null, true)
|
||||||
|
);
|
||||||
|
|
||||||
|
$argumentCollection->get('order')->default = "accessory";
|
||||||
|
|
||||||
|
$argumentCollection->get('order')->type->getKey(0)->addValue('accessory');
|
||||||
|
$argumentCollection->get('order')->type->getKey(0)->addValue('accessory_reverse');
|
||||||
|
|
||||||
|
return $argumentCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $pagination
|
||||||
|
*
|
||||||
|
* @return \Thelia\Core\Template\Element\LoopResult
|
||||||
|
*/
|
||||||
|
public function exec(&$pagination)
|
||||||
|
{
|
||||||
|
$search = AccessoryQuery::create();
|
||||||
|
|
||||||
|
$product = $this->getProduct();
|
||||||
|
$search->filterByProductId($product, Criteria::IN);
|
||||||
|
|
||||||
|
$order = $this->getOrder();
|
||||||
|
$orderByAccessory = array_search('accessory', $order);
|
||||||
|
$orderByAccessoryReverse = array_search('accessory_reverse', $order);
|
||||||
|
if($orderByAccessory !== false) {
|
||||||
|
$search->orderByPosition(Criteria::ASC);
|
||||||
|
$order[$orderByAccessory] = 'given_id';
|
||||||
|
$this->args->get('order')->setValue( implode(',', $order) );
|
||||||
|
}
|
||||||
|
if($orderByAccessoryReverse !== false) {
|
||||||
|
$search->orderByPosition(Criteria::DESC);
|
||||||
|
$order[$orderByAccessoryReverse] = 'given_id';
|
||||||
|
$this->args->get('order')->setValue( implode(',', $order) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$accessories = $this->search($search);
|
||||||
|
|
||||||
|
$accessoryIdList = array(0);
|
||||||
|
foreach ($accessories as $accessory) {
|
||||||
|
array_push($accessoryIdList, $accessory->getAccessory());
|
||||||
|
}
|
||||||
|
|
||||||
|
$receivedIdList = $this->getId();
|
||||||
|
|
||||||
|
/* if an Id list is receive, loop will only match accessories from this list */
|
||||||
|
if($receivedIdList === null) {
|
||||||
|
$this->args->get('id')->setValue( implode(',', $accessoryIdList) );
|
||||||
|
} else {
|
||||||
|
$this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $accessoryIdList)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::exec($pagination);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -83,8 +83,9 @@ class Category extends BaseLoop
|
|||||||
new Argument(
|
new Argument(
|
||||||
'order',
|
'order',
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
new Type\EnumListType('alpha', 'alpha_reverse', 'reverse')
|
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual-reverse', 'random'))
|
||||||
)
|
),
|
||||||
|
'manual'
|
||||||
),
|
),
|
||||||
Argument::createBooleanTypeArgument('random', 0),
|
Argument::createBooleanTypeArgument('random', 0),
|
||||||
Argument::createIntListTypeArgument('exclude')
|
Argument::createIntListTypeArgument('exclude')
|
||||||
@@ -139,34 +140,28 @@ class Category extends BaseLoop
|
|||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
if(null === $orders) {
|
foreach($orders as $order) {
|
||||||
$search->orderByPosition();
|
switch ($order) {
|
||||||
} else {
|
case "alpha":
|
||||||
foreach($orders as $order) {
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
||||||
switch ($order) {
|
break;
|
||||||
case "alpha":
|
case "alpha_reverse":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
$search->addDescendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
||||||
break;
|
break;
|
||||||
case "alpha_reverse":
|
case "manual-reverse":
|
||||||
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
|
$search->orderByPosition(Criteria::DESC);
|
||||||
break;
|
break;
|
||||||
case "reverse":
|
case "manual":
|
||||||
$search->orderByPosition(\Criteria::DESC);
|
$search->orderByPosition(Criteria::ASC);
|
||||||
break;
|
break;
|
||||||
default:
|
case "random":
|
||||||
$search->orderByPosition();
|
$search->clearOrderByColumns();
|
||||||
break;
|
$search->addAscendingOrderByColumn('RAND()');
|
||||||
}
|
break(2);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$random = $this->getRandom();
|
|
||||||
|
|
||||||
if ($random === true) {
|
|
||||||
$search->clearOrderByColumns();
|
|
||||||
$search->addAscendingOrderByColumn('RAND()');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
* \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -84,8 +84,9 @@ class Product extends BaseLoop
|
|||||||
new Argument(
|
new Argument(
|
||||||
'order',
|
'order',
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'manual', 'manual_reverse', 'ref', 'promo', 'new', 'random'))
|
new Type\EnumListType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'manual', 'manual_reverse', 'ref', 'promo', 'new', 'random', 'given_id'))
|
||||||
)
|
),
|
||||||
|
'manual'
|
||||||
),
|
),
|
||||||
Argument::createIntListTypeArgument('exclude'),
|
Argument::createIntListTypeArgument('exclude'),
|
||||||
Argument::createIntListTypeArgument('exclude_category'),
|
Argument::createIntListTypeArgument('exclude_category'),
|
||||||
@@ -254,54 +255,56 @@ class Product extends BaseLoop
|
|||||||
|
|
||||||
$orders = $this->getOrder();
|
$orders = $this->getOrder();
|
||||||
|
|
||||||
if(null === $orders) {
|
|
||||||
$search->orderByPosition();
|
foreach($orders as $order) {
|
||||||
} else {
|
switch ($order) {
|
||||||
foreach($orders as $order) {
|
case "alpha":
|
||||||
switch ($order) {
|
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
||||||
case "alpha":
|
break;
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
case "alpha_reverse":
|
||||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
$search->addDescendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE);
|
||||||
break;
|
break;
|
||||||
case "alpha_reverse":
|
case "reverse":
|
||||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
|
$search->orderByPosition(Criteria::DESC);
|
||||||
break;
|
break;
|
||||||
case "reverse":
|
case "min_price":
|
||||||
$search->orderByPosition(Criteria::DESC);
|
$search->orderBy('real_price', Criteria::ASC);
|
||||||
break;
|
break;
|
||||||
case "min_price":
|
case "max_price":
|
||||||
$search->orderBy('real_price', Criteria::ASC);
|
$search->orderBy('real_price', Criteria::DESC);
|
||||||
break;
|
break;
|
||||||
case "max_price":
|
case "manual":
|
||||||
$search->orderBy('real_price', Criteria::DESC);
|
if(null === $this->category || count($this->category) != 1)
|
||||||
break;
|
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
||||||
case "manual":
|
$search->orderByPosition(Criteria::ASC);
|
||||||
if(null === $this->category || count($this->category) != 1)
|
break;
|
||||||
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
case "manual_reverse":
|
||||||
$search->addAscendingOrderByColumn(ProductTableMap::POSITION);
|
if(null === $this->category || count($this->category) != 1)
|
||||||
break;
|
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
||||||
case "manual_reverse":
|
$search->orderByPosition(Criteria::DESC);
|
||||||
if(null === $this->category || count($this->category) != 1)
|
break;
|
||||||
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
|
case "ref":
|
||||||
$search->addDescendingOrderByColumn(ProductTableMap::POSITION);
|
$search->orderByRef(Criteria::ASC);
|
||||||
break;
|
break;
|
||||||
case "ref":
|
case "promo":
|
||||||
$search->addAscendingOrderByColumn(ProductTableMap::REF);
|
$search->orderByPromo(Criteria::DESC);
|
||||||
break;
|
break;
|
||||||
case "promo":
|
case "new":
|
||||||
$search->addDescendingOrderByColumn(ProductTableMap::PROMO);
|
$search->orderByNewness(Criteria::DESC);
|
||||||
break;
|
break;
|
||||||
case "new":
|
case "given_id":
|
||||||
$search->addDescendingOrderByColumn(ProductTableMap::NEWNESS);
|
if (!is_null($id)) {
|
||||||
break;
|
foreach($id as $singleId) {
|
||||||
case "random":
|
$givenIdMatched = 'given_id_matched_' . $singleId;
|
||||||
$search->clearOrderByColumns();
|
$search->withColumn(ProductTableMap::ID . "='$singleId'", $givenIdMatched);
|
||||||
$search->addAscendingOrderByColumn('RAND()');
|
$search->orderBy($givenIdMatched, Criteria::DESC);
|
||||||
break(2);
|
}
|
||||||
default:
|
}
|
||||||
$search->orderByPosition();
|
break;
|
||||||
break;
|
case "random":
|
||||||
}
|
$search->clearOrderByColumns();
|
||||||
|
$search->addAscendingOrderByColumn('RAND()');
|
||||||
|
break(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ class EnumListType implements TypeInterface
|
|||||||
$this->values = $values;
|
$this->values = $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addValue($value)
|
||||||
|
{
|
||||||
|
if(!in_array($value, $this->values))
|
||||||
|
$this->values[] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
return 'Enum list type';
|
return 'Enum list type';
|
||||||
|
|||||||
@@ -142,4 +142,9 @@ class TypeCollection implements \Iterator
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getKey($key)
|
||||||
|
{
|
||||||
|
return isset($this->types[$key]) ? $this->types[$key] : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,19 @@
|
|||||||
weight : #WEIGHT<br />
|
weight : #WEIGHT<br />
|
||||||
{/loop*}
|
{/loop*}
|
||||||
|
|
||||||
{loop name="product" type="product" order="ref" feature_values="1: foo"}
|
{*loop name="product" type="product" order="ref" feature_values="1: foo"}
|
||||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||||
price : #PRICE €<br />
|
price : #PRICE €<br />
|
||||||
promo price : #PROMO_PRICE €<br />
|
promo price : #PROMO_PRICE €<br />
|
||||||
is promo : #PROMO<br />
|
is promo : #PROMO<br />
|
||||||
is new : #NEW<br />
|
is new : #NEW<br />
|
||||||
weight : #WEIGHT<br />
|
weight : #WEIGHT<br />
|
||||||
|
{/loop*}
|
||||||
|
|
||||||
|
{loop name="product" type="product" order="ref"}
|
||||||
|
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||||
|
<h4>Accessories</h4>
|
||||||
|
{loop name="acc" type="accessory" product="#ID" order="max_price"}
|
||||||
|
#REF -
|
||||||
|
{/loop}
|
||||||
{/loop}
|
{/loop}
|
||||||
Reference in New Issue
Block a user