product loop
This commit is contained in:
@@ -33,6 +33,7 @@ use Thelia\Log\Tlog;
|
|||||||
|
|
||||||
use Thelia\Model\CategoryQuery;
|
use Thelia\Model\CategoryQuery;
|
||||||
use Thelia\Model\ProductCategoryQuery;
|
use Thelia\Model\ProductCategoryQuery;
|
||||||
|
use Thelia\Model\ProductPeer;
|
||||||
use Thelia\Model\ProductQuery;
|
use Thelia\Model\ProductQuery;
|
||||||
use Thelia\Type\TypeCollection;
|
use Thelia\Type\TypeCollection;
|
||||||
use Thelia\Type;
|
use Thelia\Type;
|
||||||
@@ -95,15 +96,14 @@ class Product extends BaseLoop
|
|||||||
new Argument(
|
new Argument(
|
||||||
'ref',
|
'ref',
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
new Type\AlphaNumStringType(),
|
new Type\AlphaNumStringListType()
|
||||||
new Type\JsonType()
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Argument::createIntListTypeArgument('category'),
|
Argument::createIntListTypeArgument('category'),
|
||||||
Argument::createBooleanTypeArgument('new'),
|
Argument::createBooleanTypeArgument('new'),
|
||||||
Argument::createBooleanTypeArgument('promo'),
|
Argument::createBooleanTypeArgument('promo'),
|
||||||
Argument::createFloatTypeArgument('min_price'),
|
Argument::createFloatTypeArgument('min_price'),
|
||||||
Argument::createFloatTypeArgument('max_prix'),
|
Argument::createFloatTypeArgument('max_price'),
|
||||||
Argument::createIntTypeArgument('min_stock'),
|
Argument::createIntTypeArgument('min_stock'),
|
||||||
Argument::createFloatTypeArgument('min_weight'),
|
Argument::createFloatTypeArgument('min_weight'),
|
||||||
Argument::createFloatTypeArgument('max_weight'),
|
Argument::createFloatTypeArgument('max_weight'),
|
||||||
@@ -114,7 +114,7 @@ class Product extends BaseLoop
|
|||||||
new Argument(
|
new Argument(
|
||||||
'order',
|
'order',
|
||||||
new TypeCollection(
|
new TypeCollection(
|
||||||
new Type\EnumType('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'category', 'manual', 'manual_reverse', 'ref', 'promo', 'new')
|
new Type\EnumType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'category', 'manual', 'manual_reverse', 'ref', 'promo', 'new'))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Argument::createBooleanTypeArgument('random', 0),
|
Argument::createBooleanTypeArgument('random', 0),
|
||||||
@@ -140,13 +140,16 @@ class Product extends BaseLoop
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($this->category)) {
|
if (!is_null($this->category)) {
|
||||||
|
$categories = CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find();
|
||||||
|
|
||||||
if(null !== $this->depth) {
|
if(null !== $this->depth) {
|
||||||
|
foreach(CategoryQuery::findAllChild($this->category, $this->depth) as $subCategory) {
|
||||||
|
$categories->prepend($subCategory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$search->filterByCategory(
|
$search->filterByCategory(
|
||||||
CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find(),
|
$categories,
|
||||||
\Criteria::IN
|
\Criteria::IN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -163,7 +166,45 @@ class Product extends BaseLoop
|
|||||||
$search->filterByNewness(0, \Criteria::EQUAL);
|
$search->filterByNewness(0, \Criteria::EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$search->filterByPriceDependingOnPromo($this->min_price, $this->max_price); //@todo review
|
if (null != $this->min_stock) {
|
||||||
|
$search->filterByQuantity($this->min_stock, \Criteria::GREATER_EQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(null !== $this->min_price) {
|
||||||
|
$search->condition('in_promo', ProductPeer::PROMO . \Criteria::EQUAL . '1')
|
||||||
|
->condition('not_in_promo', ProductPeer::PROMO . \Criteria::NOT_EQUAL . '1')
|
||||||
|
->condition('min_price2', ProductPeer::PRICE2 . \Criteria::GREATER_EQUAL . '?', $this->min_price)
|
||||||
|
->condition('min_price', ProductPeer::PRICE . \Criteria::GREATER_EQUAL . '?', $this->min_price)
|
||||||
|
->combine(array('in_promo', 'min_price2'), \Criteria::LOGICAL_AND, 'in_promo_min_price')
|
||||||
|
->combine(array('not_in_promo', 'min_price'), \Criteria::LOGICAL_AND, 'not_in_promo_min_price')
|
||||||
|
->where(array('not_in_promo_min_price', 'in_promo_min_price'), \Criteria::LOGICAL_OR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(null !== $this->max_price) {
|
||||||
|
$search->condition('in_promo', ProductPeer::PROMO . \Criteria::EQUAL . '1')
|
||||||
|
->condition('not_in_promo', ProductPeer::PROMO . \Criteria::NOT_EQUAL . '1')
|
||||||
|
->condition('max_price2', ProductPeer::PRICE2 . \Criteria::LESS_EQUAL . '?', $this->max_price)
|
||||||
|
->condition('max_price', ProductPeer::PRICE . \Criteria::LESS_EQUAL . '?', $this->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(null !== $this->min_weight) {
|
||||||
|
$search->condition('min_price2', ProductPeer::PRICE2 . \Criteria::GREATER_EQUAL . '?', $this->min_price)
|
||||||
|
->condition('min_price', ProductPeer::PRICE . \Criteria::GREATER_EQUAL . '?', $this->min_price)
|
||||||
|
->combine(array('in_promo', 'min_price2'), \Criteria::LOGICAL_AND, 'in_promo_min_price')
|
||||||
|
->combine(array('not_in_promo', 'min_price'), \Criteria::LOGICAL_AND, 'not_in_promo_min_price')
|
||||||
|
->where(array('not_in_promo_min_price', 'in_promo_min_price'), \Criteria::LOGICAL_OR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(null !== $this->max_weight) {
|
||||||
|
$search->condition('min_price2', ProductPeer::PRICE2 . \Criteria::GREATER_EQUAL . '?', $this->min_price)
|
||||||
|
->condition('min_price', ProductPeer::PRICE . \Criteria::GREATER_EQUAL . '?', $this->min_price)
|
||||||
|
->combine(array('in_promo', 'min_price2'), \Criteria::LOGICAL_AND, 'in_promo_min_price')
|
||||||
|
->combine(array('not_in_promo', 'min_price'), \Criteria::LOGICAL_AND, 'not_in_promo_min_price')
|
||||||
|
->where(array('not_in_promo_min_price', 'in_promo_min_price'), \Criteria::LOGICAL_OR);
|
||||||
|
}*/
|
||||||
|
|
||||||
if ($this->current === true) {
|
if ($this->current === true) {
|
||||||
$search->filterById($this->request->get("product_id"));
|
$search->filterById($this->request->get("product_id"));
|
||||||
@@ -264,7 +305,10 @@ class Product extends BaseLoop
|
|||||||
$loopResultRow->set("CHAPO", $product->getChapo());
|
$loopResultRow->set("CHAPO", $product->getChapo());
|
||||||
$loopResultRow->set("DESCRIPTION", $product->getDescription());
|
$loopResultRow->set("DESCRIPTION", $product->getDescription());
|
||||||
$loopResultRow->set("POSTSCRIPTUM", $product->getPostscriptum());
|
$loopResultRow->set("POSTSCRIPTUM", $product->getPostscriptum());
|
||||||
//$loopResultRow->set("CATEGORY", $product->getCategory());
|
$loopResultRow->set("PRICE", $product->getPrice());
|
||||||
|
$loopResultRow->set("PROMO_PRICE", $product->getPrice2() ? : 0);
|
||||||
|
$loopResultRow->set("PROMO", $product->getPromo());
|
||||||
|
$loopResultRow->set("NEW", $product->getNewness());
|
||||||
|
|
||||||
//$loopResultRow->set("URL", $product->getUrl());
|
//$loopResultRow->set("URL", $product->getUrl());
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
// The default HTTP status
|
// The default HTTP status
|
||||||
$this->status = 200;
|
$this->status = 200;
|
||||||
|
|
||||||
$this->registerFilter('pre', array($this, "pretest"));
|
$this->registerFilter('pre', array($this, "preThelia"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pretest($tpl_source, \Smarty_Internal_Template $template)
|
public function preThelia($tpl_source, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
|
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
|
||||||
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|default:\'#$1\'}', $new_source);
|
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|default:\'#$1\'}', $new_source);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class CategoryQuery extends BaseCategoryQuery
|
|||||||
*
|
*
|
||||||
* find all category children for a given category. an array of \Thelia\Model\Category is return
|
* find all category children for a given category. an array of \Thelia\Model\Category is return
|
||||||
*
|
*
|
||||||
* @param $categoryId the category id
|
* @param $categoryId the category id or an array of id
|
||||||
* @param int $depth max depth you want to search
|
* @param int $depth max depth you want to search
|
||||||
* @param int $currentPos don't change this param, it is used for recursion
|
* @param int $currentPos don't change this param, it is used for recursion
|
||||||
* @return \Thelia\Model\Category[]
|
* @return \Thelia\Model\Category[]
|
||||||
@@ -43,17 +43,25 @@ class CategoryQuery extends BaseCategoryQuery
|
|||||||
public static function findAllChild($categoryId, $depth = 0, $currentPos = 0)
|
public static function findAllChild($categoryId, $depth = 0, $currentPos = 0)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
$currentPos++;
|
|
||||||
|
|
||||||
if($depth == $currentPos && $depth != 0) return;
|
if(is_array($categoryId)) {
|
||||||
|
foreach($categoryId as $categorySingleId) {
|
||||||
|
$result = array_merge($result, (array) self::findAllChild($categorySingleId, $depth, $currentPos));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$currentPos++;
|
||||||
|
|
||||||
$categories = self::create()
|
if($depth == $currentPos && $depth != 0) return;
|
||||||
->filterByParent($categoryId)
|
|
||||||
->find();
|
|
||||||
|
|
||||||
foreach ($categories as $category) {
|
$categories = self::create()
|
||||||
array_push($result, $category);
|
->filterByParent($categoryId)
|
||||||
$result = array_merge($result, (array) self::findAllChild($category->getId(), $depth, $currentPos));
|
->find();
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
array_push($result, $category);
|
||||||
|
$result = array_merge($result, (array) self::findAllChild($category->getId(), $depth, $currentPos));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -18,8 +18,4 @@ use Thelia\Model\om\BaseProductPeer;
|
|||||||
*/
|
*/
|
||||||
class ProductPeer extends BaseProductPeer
|
class ProductPeer extends BaseProductPeer
|
||||||
{
|
{
|
||||||
public static function getPriceDependingOnPromoExpression()
|
|
||||||
{
|
|
||||||
return 'IF(' . self::PROMO . '=1, ' . self::PRICE2 . ', ' . self::PRICE . ')';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,4 @@ use Thelia\Model\om\BaseProductQuery;
|
|||||||
*/
|
*/
|
||||||
class ProductQuery extends BaseProductQuery
|
class ProductQuery extends BaseProductQuery
|
||||||
{
|
{
|
||||||
public function filterByPriceDependingOnPromo($minPrice = null, $maxPrice = null)
|
|
||||||
{
|
|
||||||
if ($minPrice !== null) {
|
|
||||||
$this->where(ProductPeer::getPriceDependingOnPromoExpression() . ' ' . \Criteria::GREATER_EQUAL . ' ?', $minPrice);
|
|
||||||
}
|
|
||||||
if ($maxPrice !== null) {
|
|
||||||
$this->where(ProductPeer::getPriceDependingOnPromoExpression() . ' ' . \Criteria::LESS_EQUAL . ' ?', $maxPrice);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{loop name="category0" type="category" parent="0"}
|
{*loop name="category0" type="category" parent="0"}
|
||||||
<h2>CATEGORY : #TITLE</h2>
|
<h2>CATEGORY : #TITLE</h2>
|
||||||
{loop name="category1" type="category" parent="#ID"}
|
{loop name="category1" type="category" parent="#ID"}
|
||||||
<hr />
|
<hr />
|
||||||
@@ -17,9 +17,11 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
<hr />
|
<hr />
|
||||||
<hr />
|
<hr />
|
||||||
{/loop}
|
{/loop*}
|
||||||
<h2>PRODUCTS selected by ref</h2>
|
<h2>PRODUCTS</h2>
|
||||||
{loop name="product" type="product" ref='REF1,REF2'}
|
{loop name="product" type="product" min_price="200" max_price="1000"}
|
||||||
<h3>PRODUCT : #REF / #TITLE</h3>
|
<h3>PRODUCT : #REF / #TITLE</h3>
|
||||||
#PRICE €
|
price : #PRICE €<br />
|
||||||
|
promo price : #PROMO_PRICE €<br />
|
||||||
|
is promo : #PROMO<br />
|
||||||
{/loop}
|
{/loop}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ An image from asset directory :
|
|||||||
<p>Category loop example</p>
|
<p>Category loop example</p>
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="catloop1"}
|
{loop type="category" name="catloop1"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}, children: {$NB_CHILD}
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}, children: {$NB_CHILD}
|
||||||
{ifloop rel="inner1"}
|
{ifloop rel="inner1"}
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="inner1" parent="{$ID}"}
|
{loop type="category" name="inner1" parent="{$ID}"}
|
||||||
@@ -52,7 +52,7 @@ An image from asset directory :
|
|||||||
Hey ! Loop catloop2 is not empty:
|
Hey ! Loop catloop2 is not empty:
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="catloop2" parent="12"}
|
{loop type="category" name="catloop2" parent="12"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
</ul>
|
</ul>
|
||||||
{/ifloop}
|
{/ifloop}
|
||||||
@@ -69,7 +69,7 @@ An image from asset directory :
|
|||||||
Loop catloop3 is not empty:
|
Loop catloop3 is not empty:
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="catloop3" parent="0"}
|
{loop type="category" name="catloop3" parent="0"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
</ul>
|
</ul>
|
||||||
{/ifloop}
|
{/ifloop}
|
||||||
@@ -105,20 +105,20 @@ An image from asset directory :
|
|||||||
<p>PAGE 1</p>
|
<p>PAGE 1</p>
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="catloopwithpagination1" limit="2" page="1"}
|
{loop type="category" name="catloopwithpagination1" limit="2" page="1"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
</ul>
|
</ul>
|
||||||
<p>PAGE 2</p>
|
<p>PAGE 2</p>
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="catloopwithpagination2" limit="2" page="2"}
|
{loop type="category" name="catloopwithpagination2" limit="2" page="2"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
</ul>
|
</ul>
|
||||||
<p>PAGE 1000</p>
|
<p>PAGE 1000</p>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
||||||
{loop type="category" name="catloopwithpagination1000" limit="2" page="1000"}
|
{loop type="category" name="catloopwithpagination1000" limit="2" page="1000"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
|
|
||||||
{elseloop rel="catloopwithpagination1000"}
|
{elseloop rel="catloopwithpagination1000"}
|
||||||
@@ -133,7 +133,7 @@ An image from asset directory :
|
|||||||
<p>PAGE {$current_page} :</p>
|
<p>PAGE {$current_page} :</p>
|
||||||
<ul>
|
<ul>
|
||||||
{loop type="category" name="catloopwithpaginationchoice" limit="2" page="{$current_page}"}
|
{loop type="category" name="catloopwithpaginationchoice" limit="2" page="{$current_page}"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
|
<li>{$LOOP_COUNT}/{$LOOP_TOTAL} : {$ID} {$TITLE}</li>
|
||||||
{/loop}
|
{/loop}
|
||||||
</ul>
|
</ul>
|
||||||
<p>page choice</p>
|
<p>page choice</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user