Permalink
Browse files

Better products search

Signed-off-by: Gergely <t-gely@freemail.hu>
  • Loading branch information...
1 parent d616d6c commit 815aa1efd370923f714611a97b3f842c42273ac6 @tgely committed Aug 2, 2010
Showing with 6 additions and 6 deletions.
  1. +6 −6 osCommerce/OM/Core/Site/Shop/Search.php
View
12 osCommerce/OM/Core/Site/Shop/Search.php
@@ -133,13 +133,13 @@ function execute() {
$OSCOM_CategoryTree = Registry::get('CategoryTree');
$OSCOM_Currencies = Registry::get('Currencies');
- $Qlisting = $OSCOM_Database->query('select SQL_CALC_FOUND_ROWS distinct p.*, pd.*, m.*, i.image, if(s.status, s.specials_new_products_price, null) as specials_new_products_price, if(s.status, s.specials_new_products_price, p.products_price) as final_price');
+ $Qlisting = $OSCOM_Database->query('select SQL_CALC_FOUND_ROWS distinct if(p.parent_id is NULL, p.products_id, p.parent_id) as products_id, p.parent_id, p.products_quantity, p.products_price, p.products_model, p.products_weight as products_weight_class, p.products_status, p.products_tax_class_id, p.has_children, sum(p.products_quantity) as sum_products_quantity, min(p.products_price) as min_price, pd.products_id as pd_products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_keyword, pd.products_tags, pd.products_url, pd.products_viewed, m.manufacturers_id as m_manufacturers_id, m.manufacturers_name, m.manufacturers_image, m.date_added, m.last_modified, i.image, if(s.status, s.specials_new_products_price, null) as specials_new_products_price, if(s.status, s.specials_new_products_price, min(p.products_price)) as final_price');
if ( ($this->hasPriceSet('from') || $this->hasPriceSet('to')) && (DISPLAY_PRICE_WITH_TAX == '1') ) {
$Qlisting->appendQuery(', sum(tr.tax_rate) as tax_rate');
}
- $Qlisting->appendQuery('from :table_products p left join :table_manufacturers m using(manufacturers_id) left join :table_specials s on (p.products_id = s.products_id) left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag)');
+ $Qlisting->appendQuery('from :table_products p left join :table_manufacturers m using(manufacturers_id) left join :table_specials s on (p.parent_id = s.products_id) left join :table_products_images i on (if(p.parent_id is NULL, p.products_id = i.products_id, p.parent_id = i.products_id) and i.default_flag = :default_flag)');
$Qlisting->bindInt(':default_flag', 1);
if ( ($this->hasPriceSet('from') || $this->hasPriceSet('to')) && (DISPLAY_PRICE_WITH_TAX == '1') ) {
@@ -156,17 +156,17 @@ function execute() {
$Qlisting->bindInt(':zone_id', $customer_zone_id);
}
- $Qlisting->appendQuery(', :table_products_description pd, :table_categories c, :table_products_to_categories p2c where p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id');
+ $Qlisting->appendQuery(', :table_products_description pd, :table_categories c, :table_products_to_categories p2c where p.products_status = 1 and if(p.parent_id is NULL, p.products_id = pd.products_id, p.parent_id = pd.products_id) and pd.language_id = :language_id and if(p.parent_id is NULL, p.products_id = p2c.products_id, p.parent_id = p2c.products_id) and p2c.categories_id = c.categories_id and p.has_children = 0');
$Qlisting->bindInt(':language_id', $OSCOM_Language->getID());
if ( $this->hasCategory() ) {
if ( $this->isRecursive() ) {
$subcategories_array = array($this->_category);
- $Qlisting->appendQuery('and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and p2c.categories_id in (:categories_id)');
+ $Qlisting->appendQuery('and if(p.parent_id is null, p2c.products_id = p.products_id, p2c.products_id = p.parent_id) and p2c.products_id = pd.products_id and p2c.categories_id in (:categories_id)');
$Qlisting->bindRaw(':categories_id', implode(',', $OSCOM_CategoryTree->getChildren($this->_category, $subcategories_array)));
} else {
- $Qlisting->appendQuery('and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and pd.language_id = :language_id and p2c.categories_id = :categories_id');
+ $Qlisting->appendQuery('and if(p.parent_id is null, p2c.products_id = p.products_id, p2c.products_id = p.parent_id) and p2c.products_id = pd.products_id and pd.language_id = :language_id and p2c.categories_id = :categories_id');
$Qlisting->bindInt(':language_id', $OSCOM_Language->getID());
$Qlisting->bindInt(':categories_id', $this->_category);
}
@@ -229,7 +229,7 @@ function execute() {
$Qlisting->appendQuery('group by p.products_id, tr.tax_priority');
}
- $Qlisting->appendQuery('order by');
+ $Qlisting->appendQuery('GROUP BY p.parent_id order by');
if ( isset($this->_sort_by) ) {
$Qlisting->appendQuery(':order_by :order_by_direction, pd.products_name');

0 comments on commit 815aa1e

Please sign in to comment.