From 56719a4c46c34f397bc3ce8ff146b3f8c79c0176 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 16 Jul 2013 16:57:33 +0200 Subject: [PATCH] product loop : feature_values param + fix feature_av --- .../lib/Thelia/Core/Template/Loop/Product.php | 40 +++++++++++++++++-- templates/smarty-sample/category.html | 11 ++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index bab71085d..5d07861f0 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -94,6 +94,12 @@ class Product extends BaseLoop new TypeCollection( new Type\IntToCombinedIntsListType() ) + ), + new Argument( + 'feature_values', + new TypeCollection( + new Type\IntToCombinedStringsListType() + ) ) ); } @@ -333,12 +339,40 @@ class Product extends BaseLoop if($sqlWhereString == '*') { $sqlWhereString = 'NOT ISNULL(`fa_' . $feature . '`.ID)'; } else { - $sqlWhereString = preg_replace('#(^|[^0-9])([0-9]+)([^0-9]|$)#', '\1NOT ISNULL(`fa_' . $feature . '_' . '\2`.ID)\3', $sqlWhereString); + $sqlWhereString = preg_replace('#([0-9]+)#', 'NOT ISNULL(`fa_' . $feature . '_' . '\1`.ID)', $sqlWhereString); $sqlWhereString = str_replace('&', ' AND ', $sqlWhereString); $sqlWhereString = str_replace('|', ' OR ', $sqlWhereString); } - $search->where($sqlWhereString); + $search->where("(" . $sqlWhereString . ")"); + } + } + + $feature_values = $this->getFeature_values(); + + if(null !== $feature_values) { + foreach($feature_values as $feature => $feature_choice) { + foreach($feature_choice['values'] as $feature_value) { + $featureAlias = 'fv_' . $feature; + if($feature_value != '*') + $featureAlias .= '_' . $feature_value; + $search->joinFeatureProd($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); + } + + /* format for mysql */ + $sqlWhereString = $feature_choice['expression']; + if($sqlWhereString == '*') { + $sqlWhereString = 'NOT ISNULL(`fv_' . $feature . '`.ID)'; + } else { + $sqlWhereString = preg_replace('#([a-zA-Z0-9_\-]+)#', 'NOT ISNULL(`fv_' . $feature . '_' . '\1`.ID)', $sqlWhereString); + $sqlWhereString = str_replace('&', ' AND ', $sqlWhereString); + $sqlWhereString = str_replace('|', ' OR ', $sqlWhereString); + } + + $search->where("(" . $sqlWhereString . ")"); } } @@ -373,8 +407,6 @@ class Product extends BaseLoop $loopResultRow->set("PROMO", $product->getPromo()); $loopResultRow->set("NEW", $product->getNewness()); - //$loopResultRow->set("URL", $product->getUrl()); - $loopResult->addRow($loopResultRow); } diff --git a/templates/smarty-sample/category.html b/templates/smarty-sample/category.html index 275197848..ef97c92e1 100755 --- a/templates/smarty-sample/category.html +++ b/templates/smarty-sample/category.html @@ -28,7 +28,16 @@ weight : #WEIGHT
{/loop*} -{loop name="product" type="product" order="ref" feature_available="1: (1 | 2) , 2: 4, 3: 433"} +{*loop name="product" type="product" order="ref" feature_available="1: (1 | 2) , 2: 4, 3: 433"} +

PRODUCT : #REF / #TITLE

+ price : #PRICE €
+ promo price : #PROMO_PRICE €
+ is promo : #PROMO
+ is new : #NEW
+ weight : #WEIGHT
+{/loop*} + +{loop name="product" type="product" order="ref" feature_values="1: foo"}

PRODUCT : #REF / #TITLE

price : #PRICE €
promo price : #PROMO_PRICE €