Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r4043 -r4052 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4043) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4052) @@ -658,15 +658,23 @@ // field processing $weight_sum = 0; + + $alias_counter = 0; + + $custom_fields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); + if ($custom_fields) { + $custom_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); + $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$product_table.'.ResourceId = custom_data.ResourceId'; + } + foreach($field_list as $key => $field) { $options = $object->getFieldOptions($field); $local_table = TABLE_PREFIX.$search_config[$field]['TableName']; $weight_sum += $search_config[$field]['Priority']; // counting weight sum; used when making relevance clause // processing multilingual fields - if($options['formatter'] == 'kMultiLanguage') - { + if (getArrayValue($options, 'formatter') == 'kMultiLanguage') { $field_list[$key] = 'l'.$lang.'_'.$field; } @@ -691,30 +699,26 @@ } else { - $exploded = explode('.', $foreign_field); + $exploded = explode('.', $foreign_field); // format: table.field_name $foreign_table = TABLE_PREFIX.$exploded[0]; - - if($search_config[$field]['CustomFieldId']) { - $exploded[1] = 'l'.$lang.'_'.$exploded[1]; - } - + $alias_counter++; $alias = 't'.$alias_counter; $field_list[$key] = $alias.'.'.$exploded[1]; $join_clause = str_replace('{ForeignTable}', $alias, $search_config[$field]['JoinClause']); $join_clause = str_replace('{LocalTable}', $product_table, $join_clause); - if($search_config[$field]['CustomFieldId']) - { - $join_clause .= ' AND '.$alias.'.CustomFieldId='.$search_config[$field]['CustomFieldId']; - } + $join_clauses[] = ' LEFT JOIN '.$foreign_table.' '.$alias.' ON '.$join_clause; } } - else - { + else { // processing fields from local table + if ($search_config[$field]['CustomFieldId']) { + $local_table = 'custom_data'; + $field_list[$key] = 'l'.$lang.'_cust_'.array_search($field_list[$key], $custom_fields); + } $field_list[$key] = $local_table.'.'.$field_list[$key]; } } @@ -860,9 +864,9 @@ $revelance_parts[] = 'IF('.$field.' LIKE "%'.$keyword.'%", '.$config_elem['value']['Priority'].', 0)'; } } - $rel_keywords = $this->Application->ConfigValue('SearchRel_DefaultKeyword_products') / 100; - $rel_pop = $this->Application->ConfigValue('SearchRel_DefaultPop_products') / 100; - $rel_rating = $this->Application->ConfigValue('SearchRel_DefaultRating_products') / 100; + $rel_keywords = $this->Application->ConfigValue('SearchRel_Keyword_products') / 100; + $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_products') / 100; + $rel_rating = $this->Application->ConfigValue('SearchRel_Rating_products') / 100; $relevance_clause = '('.implode(' + ', $revelance_parts).') / '.$weight_sum.' * '.$rel_keywords; $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; @@ -959,6 +963,13 @@ 'isnot' => '(%1$s != %2$s OR %1$s IS NULL)'); $alias_counter = 0; + + $custom_fields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); + if ($custom_fields) { + $custom_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); + $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$product_table.'.ResourceId = custom_data.ResourceId'; + } + $weight_sum = 0; // processing fields and preparing conditions foreach($search_config as $record) @@ -974,18 +985,15 @@ $weight_sum += $record['Priority']; // counting weight sum; used when making relevance clause // processing multilingual fields - if($options['formatter'] == 'kMultiLanguage') - { + if (getArrayValue($options, 'formatter') == 'kMultiLanguage') { $field_name = 'l'.$lang.'_'.$field; } - else - { + else { $field_name = $field; } - + // processing fields from other tables - if($foreign_field = $record['ForeignField']) - { + if ($foreign_field = $record['ForeignField']) { $exploded = explode(':', $foreign_field, 2); if($exploded[0] == 'CALC') { @@ -1000,8 +1008,7 @@ $condition_mode = 'HAVING'; } - else - { + else { $exploded = explode('.', $foreign_field); $foreign_table = TABLE_PREFIX.$exploded[0]; @@ -1027,6 +1034,11 @@ else { // processing fields from local table + if ($record['CustomFieldId']) { + $local_table = 'custom_data'; + $field_name = 'l'.$lang.'_cust_'.array_search($field_name, $custom_fields); + } + $field_name = $local_table.'.'.$field_name; } @@ -1172,9 +1184,9 @@ // making relevance clause if($relevance_parts) { - $rel_keywords = $this->Application->ConfigValue('SearchRel_DefaultKeyword_products') / 100; - $rel_pop = $this->Application->ConfigValue('SearchRel_DefaultPop_products') / 100; - $rel_rating = $this->Application->ConfigValue('SearchRel_DefaultRating_products') / 100; + $rel_keywords = $this->Application->ConfigValue('SearchRel_Keyword_products') / 100; + $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_products') / 100; + $rel_rating = $this->Application->ConfigValue('SearchRel_Rating_products') / 100; $relevance_clause = '('.implode(' + ', $relevance_parts).') / '.$weight_sum.' * '.$rel_keywords; $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating;