diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index d1e6569fa..c8d0ef53f 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -6,6 +6,7 @@ + diff --git a/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php b/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php index e8c44da03..86c11edfb 100755 --- a/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php +++ b/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php @@ -72,12 +72,25 @@ class Argument ); } + public static function createFloatTypeArgument($name, $default=null, $mandatory=false, $empty=true) + { + return new Argument( + $name, + new TypeCollection( + new Type\FloatType() + ), + $default, + $mandatory, + $empty + ); + } + public static function createBooleanTypeArgument($name, $default=null, $mandatory=false, $empty=true) { return new Argument( $name, new TypeCollection( - new Type\BoolType() + new Type\BooleanType() ), $default, $mandatory, diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 0d3426dfa..161727f51 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -84,9 +84,9 @@ class Category extends BaseLoop return new ArgumentCollection( Argument::createIntListTypeArgument('id'), Argument::createIntTypeArgument('parent'), - Argument::createIntTypeArgument('current'), - Argument::createIntTypeArgument('not_empty', 0), - Argument::createIntTypeArgument('visible', 1), + Argument::createBooleanTypeArgument('current'), + Argument::createBooleanTypeArgument('not_empty', 0), + Argument::createBooleanTypeArgument('visible', 1), Argument::createAnyTypeArgument('link'), new Argument( 'order', @@ -94,7 +94,7 @@ class Category extends BaseLoop new Type\EnumType('alpha', 'alpha_reverse', 'reverse') ) ), - Argument::createIntTypeArgument('random', 0), + Argument::createBooleanTypeArgument('random', 0), Argument::createIntListTypeArgument('exclude') ); } @@ -109,28 +109,28 @@ class Category extends BaseLoop $search = CategoryQuery::create(); if (!is_null($this->id)) { - $search->filterById(explode(',', $this->id), \Criteria::IN); + $search->filterById($this->id, \Criteria::IN); } if (!is_null($this->parent)) { $search->filterByParent($this->parent); } - if ($this->current == 1) { + if ($this->current === true) { $search->filterById($this->request->get("category_id")); - } elseif (null !== $this->current && $this->current == 0) { + } elseif ($this->current === false) { $search->filterById($this->request->get("category_id"), \Criteria::NOT_IN); } if (!is_null($this->exclude)) { - $search->filterById(explode(",", $this->exclude), \Criteria::NOT_IN); + $search->filterById($this->exclude, \Criteria::NOT_IN); } if (!is_null($this->link)) { $search->filterByLink($this->link); } - $search->filterByVisible($this->visible); + $search->filterByVisible($this->visible ? 1 : 0); switch ($this->order) { case "alpha": @@ -147,7 +147,7 @@ class Category extends BaseLoop break; } - if ($this->random == 1) { + if ($this->random === true) { $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); } diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index bdafb2794..38d6d9b75 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -31,6 +31,8 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Log\Tlog; +use Thelia\Model\CategoryQuery; +use Thelia\Model\ProductCategoryQuery; use Thelia\Model\ProductQuery; use Thelia\Type\TypeCollection; use Thelia\Type; @@ -68,13 +70,17 @@ class Product extends BaseLoop public $id; public $ref; public $category; - public $price; - public $price2; + public $new; public $promo; - public $newness; - public $visible; - public $weight; + public $min_price; + public $max_price; + public $min_stock; + public $min_weight; + public $max_weight; public $current; + public $current_category; + public $depth; + public $visible; public $order; public $random; public $exclude; @@ -94,25 +100,23 @@ class Product extends BaseLoop ), Argument::createIntListTypeArgument('category'), Argument::createBooleanTypeArgument('new'), - Argument::createIntTypeArgument('promo'), - Argument::createIntTypeArgument('max_prix'), - Argument::createIntTypeArgument('min_price'), + Argument::createBooleanTypeArgument('promo'), + Argument::createFloatTypeArgument('min_price'), + Argument::createFloatTypeArgument('max_prix'), Argument::createIntTypeArgument('min_stock'), - Argument::createIntTypeArgument('min_weight'), - Argument::createIntTypeArgument('max_weight'), - Argument::createIntTypeArgument('current'), - Argument::createIntTypeArgument('current_category'), + Argument::createFloatTypeArgument('min_weight'), + Argument::createFloatTypeArgument('max_weight'), + Argument::createBooleanTypeArgument('current'), + Argument::createBooleanTypeArgument('current_category'), Argument::createIntTypeArgument('depth'), - Argument::createIntTypeArgument('not_empty', 0), - Argument::createIntTypeArgument('visible', 1), - Argument::createAnyTypeArgument('link'), + Argument::createBooleanTypeArgument('visible', 1), new Argument( 'order', new TypeCollection( - new Type\EnumType('title_alpha', 'title_alpha_reverse', 'reverse', 'min_price', 'max_price', 'category', 'manual', 'ref', 'promo') + new Type\EnumType('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'category', 'manual', 'manual_reverse', 'ref', 'promo', 'new') ) ), - Argument::createIntTypeArgument('random', 0), + Argument::createBooleanTypeArgument('random', 0), Argument::createIntListTypeArgument('exclude') ); } @@ -124,28 +128,65 @@ class Product extends BaseLoop */ public function exec(&$pagination) { - $search = CategoryQuery::create(); + $search = ProductQuery::create(); if (!is_null($this->id)) { - $search->filterById(explode(',', $this->id), \Criteria::IN); + $search->filterById($this->id, \Criteria::IN); } - if (!is_null($this->parent)) { - $search->filterByParent($this->parent); + if (!is_null($this->ref)) { + $search->filterByRef($this->ref, \Criteria::IN); } - if ($this->current == 1) { - $search->filterById($this->request->get("category_id")); - } elseif (null !== $this->current && $this->current == 0) { - $search->filterById($this->request->get("category_id"), \Criteria::NOT_IN); + if (!is_null($this->category)) { + $search->filterByCategory( + CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find(), + \Criteria::IN + ); } - if (!is_null($this->exclude)) { - $search->filterById(explode(",", $this->exclude), \Criteria::NOT_IN); + if ($this->new === true) { + $search->filterByNewness(1, \Criteria::EQUAL); + } else if($this->new === false) { + $search->filterByNewness(0, \Criteria::EQUAL); } - if (!is_null($this->link)) { - $search->filterByLink($this->link); + if ($this->promo === true) { + $search->filterByPromo(1, \Criteria::EQUAL); + } else if($this->promo === false) { + $search->filterByNewness(0, \Criteria::EQUAL); + } + + $search->filterByPriceDependingOnPromo($this->min_price, $this->max_price); //@todo review + + if ($this->current === true) { + $search->filterById($this->request->get("product_id")); + } elseif($this->current === false) { + $search->filterById($this->request->get("product_id"), \Criteria::NOT_IN); + } + + if ($this->current_category === true) { + $search->filterByCategory( + CategoryQuery::create()->filterByProduct( + ProductCategoryQuery::create()->filterByProductId( + $this->request->get("product_id"), + \Criteria::EQUAL + )->find(), + \Criteria::IN + )->find(), + \Criteria::IN + ); + } elseif($this->current_category === false) { + $search->filterByCategory( + CategoryQuery::create()->filterByProduct( + ProductCategoryQuery::create()->filterByProductId( + $this->request->get("product_id"), + \Criteria::EQUAL + )->find(), + \Criteria::IN + )->find(), + \Criteria::NOT_IN + ); } $search->filterByVisible($this->visible); @@ -160,16 +201,44 @@ class Product extends BaseLoop case "reverse": $search->orderByPosition(\Criteria::DESC); break; + /*case "min_price": + $search->orderByPosition(\Criteria::DESC); + break; + case "max_price": + $search->orderByPosition(\Criteria::DESC); + break; + case "category": + $search->orderByPosition(\Criteria::DESC); + break;*/ + case "manual": + $search->addAscendingOrderByColumn(\Thelia\Model\ProductPeer::POSITION); + break; + case "manual_reverse": + $search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::POSITION); + break; + case "ref": + $search->addAscendingOrderByColumn(\Thelia\Model\ProductPeer::REF); + break; + case "promo": + $search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::PROMO); + break; + case "new": + $search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::NEWNESS); + break; default: $search->orderByPosition(); break; } - if ($this->random == 1) { + if ($this->random === true) { $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); } + if (!is_null($this->exclude)) { + $search->filterById($this->exclude, \Criteria::NOT_IN); + } + /** * \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation. * @@ -177,24 +246,21 @@ class Product extends BaseLoop */ $search->joinWithI18n($this->request->getSession()->get('locale', 'en_US'), \Criteria::INNER_JOIN); - $categories = $this->search($search, $pagination); + $products = $this->search($search, $pagination); $loopResult = new LoopResult(); - foreach ($categories as $category) { - - if ($this->not_empty && $category->countAllProducts() == 0) continue; - + foreach ($products as $product) { $loopResultRow = new LoopResultRow(); - $loopResultRow->set("TITLE",$category->getTitle()); - $loopResultRow->set("CHAPO", $category->getChapo()); - $loopResultRow->set("DESCRIPTION", $category->getDescription()); - $loopResultRow->set("POSTSCRIPTUM", $category->getPostscriptum()); - $loopResultRow->set("PARENT", $category->getParent()); - $loopResultRow->set("ID", $category->getId()); - $loopResultRow->set("URL", $category->getUrl()); - $loopResultRow->set("LINK", $category->getLink()); - $loopResultRow->set("NB_CHILD", $category->countChild()); + $loopResultRow->set("ID", $product->getId()); + $loopResultRow->set("REF",$product->getRef()); + $loopResultRow->set("TITLE",$product->getTitle()); + $loopResultRow->set("CHAPO", $product->getChapo()); + $loopResultRow->set("DESCRIPTION", $product->getDescription()); + $loopResultRow->set("POSTSCRIPTUM", $product->getPostscriptum()); + //$loopResultRow->set("CATEGORY", $product->getCategory()); + + //$loopResultRow->set("URL", $product->getUrl()); $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 3bc019c59..e02db2726 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -78,7 +78,6 @@ class TheliaLoop implements SmartyPluginInterface if (empty($params['name'])) throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments"); - if (empty($params['type'])) throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments"); @@ -279,7 +278,7 @@ class TheliaLoop implements SmartyPluginInterface $argumentsCollection = $loop->getArgs(); foreach( $argumentsCollection as $argument ) { - $value = isset($smartyParam[$argument->name]) ? $smartyParam[$argument->name] : null; + $value = isset($smartyParam[$argument->name]) ? (string)$smartyParam[$argument->name] : null; /* check if mandatory */ if($value === null && $argument->mandatory) { @@ -304,11 +303,13 @@ class TheliaLoop implements SmartyPluginInterface /* set default */ /* did it as last checking for we consider default value is acceptable no matter type or empty restriction */ - if($value === null) { - $value = $argument->default; + if($value === null && $argument->default !== null) { + $value = (string)$argument->default; } - $loop->{$argument->name} = $value === null ? null : $argument->type->getFormatedValue($value); + $test = $argument->type->getFormatedValue($value); + + $loop->{$argument->name} = $value === null ? null : $test; } if (!empty($faultActor)) { diff --git a/core/lib/Thelia/Model/ProductPeer.php b/core/lib/Thelia/Model/ProductPeer.php index 63e4f6970..b8b356d3c 100755 --- a/core/lib/Thelia/Model/ProductPeer.php +++ b/core/lib/Thelia/Model/ProductPeer.php @@ -18,4 +18,8 @@ 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 23c807592..cbd9893ae 100755 --- a/core/lib/Thelia/Model/ProductQuery.php +++ b/core/lib/Thelia/Model/ProductQuery.php @@ -18,4 +18,15 @@ 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 new file mode 100755 index 000000000..c6c70c69a --- /dev/null +++ b/templates/smarty-sample/category.html @@ -0,0 +1,8 @@ +{loop name="category0" type="category" parent="0"} +

1 - CATEGORY : #TITLE

+

+ {loop name="category1" type="category" parent="#ID"} +

2 - SUBCATEGORY : #TITLE

+ {/loop} +

1bis - CATEGORY : #TITLE

+{/loop} \ No newline at end of file