From f27e979ba5dcb5d5990231a491dcd0d98086dc3c Mon Sep 17 00:00:00 2001 From: rGaillard Date: Thu, 28 Jun 2012 21:48:21 +0000 Subject: [PATCH] [-] BO: Fix PSCFV-2818 application of specific price rules when multiple conditions of same type in the same group --- classes/SpecificPriceRule.php | 53 ++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/classes/SpecificPriceRule.php b/classes/SpecificPriceRule.php index bf2e54f18..283977665 100755 --- a/classes/SpecificPriceRule.php +++ b/classes/SpecificPriceRule.php @@ -185,32 +185,51 @@ class SpecificPriceRuleCore extends ObjectModel $where = '('; foreach ($conditions_group as $id_condition_group => $condition_group) { + $fields = array( + 'category' => array( + 'name' => 'cp.id_category', + 'values' => array() + ), + 'manufacturer' => array( + 'name' => 'p.id_manufacturer', + 'values' => array(), + ), + 'supplier' => array( + 'name' => 'p.id_supplier', + 'values' => array() + ), + 'feature' => array( + 'name' => 'fp.id_feature_value', + 'values' => array() + ), + 'attribute' => array( + 'name'=> 'pac.id_attribute', + 'values' => array() + ) + ); + foreach ($condition_group as $condition) { - $field = false; if ($condition['type'] == 'category') - { - $field = 'cp.id_category'; $categories = true; - } - elseif ($condition['type'] == 'manufacturer') - $field = 'p.id_manufacturer'; - elseif ($condition['type'] == 'supplier') - $field = 'p.id_supplier'; elseif ($condition['type'] == 'feature') - { - $field = 'fp.id_feature_value'; $features = true; - } elseif ($condition['type'] == 'attribute') - { - $field = 'pac.id_attribute'; $attributes = true; - } - if ($field) - $where .= $field.'='.(int)$condition['value'].' AND '; - + + $fields[$condition['type']]['values'][] = $condition['value']; } + + foreach ($fields as $field) + { + if (!$n_conditions = count($field['values'])) + continue; + + $where .= $field['name'].' IN ('.implode(',', array_map('intval', $field['values'])).') AND '; + if ($n_conditions > 1) + $query->having('COUNT('.bqSQL($field['name']).') >='.(int)$n_conditions); + } + $where = rtrim($where, ' AND ').') OR ('; } $where = rtrim($where, 'OR (');