diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 80d65a703..b67041fb6 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -327,11 +327,23 @@ class Product extends BaseLoop $search->joinFeatureProd('fa2', Criteria::LEFT_JOIN)->addJoinCondition('fa2', "'fa2.PRODUCT_ID' = 3"); */ - $x = new Join(); - $x->addExplicitCondition('product', 'id', null, 'feature_prod', 'PRODUCT_ID', 'fa0', Criteria::EQUAL); - $search->addJoinObject( - $x - ); + /* pas mieux + $x = new Join(ProductTableMap::ID, FeatureProdTableMap::PRODUCT_ID, Criteria::LEFT_JOIN); + $x->setRightTableAlias('fa0'); + $search->addJoinObject($x, 'fa0')->addJoinCondition('fa0', "PRODUCT_ID = ?", 0); + */ + + foreach($feature_available as $feature => $feature_choice) { + foreach($feature_choice['values'] as $feature_av) { + $featureAlias = 'fa_' . $feature . '_' . $feature_av; + $search->joinFeatureProd($featureAlias, Criteria::LEFT_JOIN) + ->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT) + ->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_AV_ID = ?", $feature_av, null, \PDO::PARAM_INT); + } + $bigDealFeatureWhereCondition = str_replace('&', ' AND ', $feature_choice['values']); + } + + /* * ne marche pas de cette façon : diff --git a/core/lib/Thelia/Tests/Type/BooleanTypeTest.php b/core/lib/Thelia/Tests/Type/BooleanTypeTest.php index d91cc6bc9..26a85b31b 100755 --- a/core/lib/Thelia/Tests/Type/BooleanTypeTest.php +++ b/core/lib/Thelia/Tests/Type/BooleanTypeTest.php @@ -35,21 +35,23 @@ class BooleanTypeTest extends \PHPUnit_Framework_TestCase public function testBooleanType() { $booleanType = new BooleanType(); - $this->assertTrue($booleanType->isValid('y')); + $this->assertTrue($booleanType->isValid('1')); $this->assertTrue($booleanType->isValid('yes')); $this->assertTrue($booleanType->isValid('true')); $this->assertTrue($booleanType->isValid('no')); - $this->assertTrue($booleanType->isValid('n')); + $this->assertTrue($booleanType->isValid('off')); + $this->assertTrue($booleanType->isValid(1)); $this->assertTrue($booleanType->isValid('false')); $this->assertFalse($booleanType->isValid('foo')); - $this->assertFalse($booleanType->isValid(5)); + $this->assertFalse($booleanType->isValid(2)); } public function testFormatBooleanType() { $booleanType = new BooleanType(); - $this->assertTrue($booleanType->getFormattedValue('yes')); - $this->assertFalse($booleanType->getFormattedValue('no')); - $this->assertNull($booleanType->getFormattedValue('foo')); + $this->assertTrue($booleanType->getFormattedValue('on')); + $this->assertFalse($booleanType->getFormattedValue('0')); + $this->assertFalse($booleanType->getFormattedValue(0)); + $this->assertNull($booleanType->getFormattedValue(3)); } } diff --git a/core/lib/Thelia/Type/BooleanType.php b/core/lib/Thelia/Type/BooleanType.php index 0c85d3ba8..e7bbea786 100755 --- a/core/lib/Thelia/Type/BooleanType.php +++ b/core/lib/Thelia/Type/BooleanType.php @@ -30,19 +30,6 @@ namespace Thelia\Type; class BooleanType implements TypeInterface { - protected $trueValuesArray = array( - '1', - 'true', - 'yes', - 'y', - ); - protected $falseValuesArray = array( - '0', - 'false', - 'no', - 'n', - ); - public function getType() { return 'Boolean type'; @@ -50,11 +37,11 @@ class BooleanType implements TypeInterface public function isValid($value) { - return in_array($value, $this->trueValuesArray) || in_array($value, $this->falseValuesArray); + return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null; } public function getFormattedValue($value) { - return $this->isValid($value) ? ( in_array($value, $this->trueValuesArray) ) : null; + return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); } } diff --git a/core/lib/Thelia/Type/IntToCombinedIntsList.php b/core/lib/Thelia/Type/IntToCombinedIntsList.php index f5ac6b58c..adefb0bb8 100755 --- a/core/lib/Thelia/Type/IntToCombinedIntsList.php +++ b/core/lib/Thelia/Type/IntToCombinedIntsList.php @@ -43,8 +43,49 @@ class IntToCombinedIntsList implements TypeInterface return false; if(filter_var($parts[0], FILTER_VALIDATE_INT) === false) return false; - if(!preg_match('#^([0-9]+([\&\|]{1}[0-9]+)*|\*)$#', $parts[1])) + + /* delete all spaces and parentheses */ + $noSpaceString = preg_replace('#[\s]#', '', $parts[1]); + $noParentheseString = preg_replace('#[\(\)]#', '', $noSpaceString); + + if(!preg_match('#^([0-9]+([\&\|][0-9]+)*|\*)$#', $noParentheseString)) return false; + + /* check parenteses use */ + $openingParenthesesCount = 0; + $closingParenthesesCount = 0; + + for($i=0; $i preg_split( "#(&|\|)#", $parts[1]), + "expression" => $parts[0], + );*/ + + $x = 1; } return $return; diff --git a/templates/smarty-sample/category.html b/templates/smarty-sample/category.html index 1335132ea..d95ff1763 100755 --- a/templates/smarty-sample/category.html +++ b/templates/smarty-sample/category.html @@ -27,7 +27,7 @@ is new : #NEW
weight : #WEIGHT
{/loop*} -{loop name="product" type="product" feature_available="15:1|2|3,12:5&8|6,6:*"} +{loop name="product" type="product" feature_available="1: (1 | 2) , 2: 4"}

PRODUCT : #REF / #TITLE

price : #PRICE €
promo price : #PROMO_PRICE €