features in product loop

This commit is contained in:
Etienne Roudeix
2013-07-10 16:59:34 +02:00
parent 74f205831c
commit ab7a9b3cd8
5 changed files with 81 additions and 29 deletions

View File

@@ -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 :

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -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<strlen($noSpaceString); $i++) {
$char = $noSpaceString[$i];
if($char == '(') {
/* must be :
* - after a &| or () or at the begining of expression
* - before a number or ()
* must not be :
* - at the end of expression
*/
if(($i!=0 && !preg_match('#[\(\)\&\|]#', $noSpaceString[$i-1])) || !isset($noSpaceString[$i+1]) || !preg_match('#[\(\)0-9]#', $noSpaceString[$i+1])) {
return false;
}
$openingParenthesesCount++;
} elseif($char == ')') {
/* must be :
* - after a number or ()
* - before a &| or () or at the end of expression
* must not be :
* - at the begining of expression
* - if no ( remain unclose
*/
if($i == 0 || !preg_match('#[\(\)0-9]#', $noSpaceString[$i-1]) || (isset($noSpaceString[$i+1]) && !preg_match('#[\(\)\&\|]#', $noSpaceString[$i+1])) || $openingParenthesesCount-$closingParenthesesCount==0) {
return false;
}
$closingParenthesesCount++;
}
}
if($openingParenthesesCount != $closingParenthesesCount) {
return false;
}
}
return true;
@@ -57,7 +98,17 @@ class IntToCombinedIntsList implements TypeInterface
foreach(explode(',', $values) as $intToCombinedInts) {
$parts = explode(':', $intToCombinedInts);
$return[$parts[0]] = $parts[1];
/* delete all spaces and parentheses */
$noParentheseString = preg_replace('#[\s\(\)]#', '', $parts[1]);
//$return[$parts[0]] = preg_match_all("#^([0-9]+([\&\|][0-9]+)*|\*)$#", $parts[1]);
/*array(
"values" => preg_split( "#(&|\|)#", $parts[1]),
"expression" => $parts[0],
);*/
$x = 1;
}
return $return;

View File

@@ -27,7 +27,7 @@
is new : #NEW<br />
weight : #WEIGHT<br />
{/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"}
<h3>PRODUCT : #REF / #TITLE</h3>
price : #PRICE €<br />
promo price : #PROMO_PRICE €<br />