diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index c4447d4c6..4a3510196 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -33,6 +33,7 @@ use Thelia\Log\Tlog; use Thelia\Model\CategoryQuery; use Thelia\Model\ProductCategoryQuery; +use Thelia\Model\ProductPeer; use Thelia\Model\ProductQuery; use Thelia\Type\TypeCollection; use Thelia\Type; @@ -95,15 +96,14 @@ class Product extends BaseLoop new Argument( 'ref', new TypeCollection( - new Type\AlphaNumStringType(), - new Type\JsonType() + new Type\AlphaNumStringListType() ) ), Argument::createIntListTypeArgument('category'), Argument::createBooleanTypeArgument('new'), Argument::createBooleanTypeArgument('promo'), Argument::createFloatTypeArgument('min_price'), - Argument::createFloatTypeArgument('max_prix'), + Argument::createFloatTypeArgument('max_price'), Argument::createIntTypeArgument('min_stock'), Argument::createFloatTypeArgument('min_weight'), Argument::createFloatTypeArgument('max_weight'), @@ -114,7 +114,7 @@ class Product extends BaseLoop new Argument( 'order', 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), @@ -140,13 +140,16 @@ class Product extends BaseLoop } if (!is_null($this->category)) { + $categories = CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find(); if(null !== $this->depth) { - + foreach(CategoryQuery::findAllChild($this->category, $this->depth) as $subCategory) { + $categories->prepend($subCategory); + } } $search->filterByCategory( - CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find(), + $categories, \Criteria::IN ); } @@ -163,7 +166,45 @@ class Product extends BaseLoop $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) { $search->filterById($this->request->get("product_id")); @@ -264,7 +305,10 @@ class Product extends BaseLoop $loopResultRow->set("CHAPO", $product->getChapo()); $loopResultRow->set("DESCRIPTION", $product->getDescription()); $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()); diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 42a79a6d4..ac83bf57e 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -72,10 +72,10 @@ class SmartyParser extends Smarty implements ParserInterface // The default HTTP status $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|default:\'#$1\'}', $new_source); diff --git a/core/lib/Thelia/Model/CategoryQuery.php b/core/lib/Thelia/Model/CategoryQuery.php index 61ff52dfb..ae8f984eb 100755 --- a/core/lib/Thelia/Model/CategoryQuery.php +++ b/core/lib/Thelia/Model/CategoryQuery.php @@ -35,7 +35,7 @@ class CategoryQuery extends BaseCategoryQuery * * 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 $currentPos don't change this param, it is used for recursion * @return \Thelia\Model\Category[] @@ -43,17 +43,25 @@ class CategoryQuery extends BaseCategoryQuery public static function findAllChild($categoryId, $depth = 0, $currentPos = 0) { $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() - ->filterByParent($categoryId) - ->find(); + if($depth == $currentPos && $depth != 0) return; - foreach ($categories as $category) { - array_push($result, $category); - $result = array_merge($result, (array) self::findAllChild($category->getId(), $depth, $currentPos)); + $categories = self::create() + ->filterByParent($categoryId) + ->find(); + + + foreach ($categories as $category) { + array_push($result, $category); + $result = array_merge($result, (array) self::findAllChild($category->getId(), $depth, $currentPos)); + } } return $result; diff --git a/core/lib/Thelia/Model/ProductPeer.php b/core/lib/Thelia/Model/ProductPeer.php index b8b356d3c..63e4f6970 100755 --- a/core/lib/Thelia/Model/ProductPeer.php +++ b/core/lib/Thelia/Model/ProductPeer.php @@ -18,8 +18,4 @@ use Thelia\Model\om\BaseProductPeer; */ class ProductPeer extends BaseProductPeer { - public static function getPriceDependingOnPromoExpression() - { - return 'IF(' . self::PROMO . '=1, ' . self::PRICE2 . ', ' . self::PRICE . ')'; - } } diff --git a/core/lib/Thelia/Model/ProductQuery.php b/core/lib/Thelia/Model/ProductQuery.php index cbd9893ae..23c807592 100755 --- a/core/lib/Thelia/Model/ProductQuery.php +++ b/core/lib/Thelia/Model/ProductQuery.php @@ -18,15 +18,4 @@ use Thelia\Model\om\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; - } } diff --git a/templates/smarty-sample/category.html b/templates/smarty-sample/category.html index 0055dee99..a4b704b68 100755 --- a/templates/smarty-sample/category.html +++ b/templates/smarty-sample/category.html @@ -1,4 +1,4 @@ -{loop name="category0" type="category" parent="0"} +{*loop name="category0" type="category" parent="0"}

CATEGORY : #TITLE

{loop name="category1" type="category" parent="#ID"}
@@ -17,9 +17,11 @@ {/loop}

-{/loop} -

PRODUCTS selected by ref

-{loop name="product" type="product" ref='REF1,REF2'} +{/loop*} +

PRODUCTS

+{loop name="product" type="product" min_price="200" max_price="1000"}

PRODUCT : #REF / #TITLE

- #PRICE € + price : #PRICE €
+ promo price : #PROMO_PRICE €
+ is promo : #PROMO
{/loop} diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index 24f964510..d24efa89c 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -32,7 +32,7 @@ An image from asset directory :

Category loop example