Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better products listing

Signed-off-by: Gergely <t-gely@freemail.hu>
  • Loading branch information...
commit d616d6c0126ce5e5bead1e580c1f88522607b42b 1 parent 26dbd8c
@tgely authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 osCommerce/OM/Core/Site/Shop/Products.php
View
10 osCommerce/OM/Core/Site/Shop/Products.php
@@ -61,7 +61,7 @@ function setSortBy($field, $direction = '+') {
$this->_sort_by = 'm.manufacturers_name';
break;
case 'quantity':
- $this->_sort_by = 'p.products_quantity';
+ $this->_sort_by = 'sum_products_quantity';
break;
case 'weight':
$this->_sort_by = 'p.products_weight';
@@ -86,7 +86,7 @@ function execute() {
$OSCOM_Language = Registry::get('Language');
$OSCOM_CategoryTree = Registry::get('CategoryTree');
- $Qlisting = $OSCOM_Database->query('select distinct p.products_id from :table_products p left join :table_product_attributes pa on (p.products_id = pa.products_id) left join :table_templates_boxes tb on (pa.id = tb.id and tb.code = "Manufacturers"), :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 = $OSCOM_Database->query('select distinct if(p.parent_id is null, p.products_id, p.parent_id) as products_id, sum(p.products_quantity) as sum_products_quantity, min(p.products_price) as final_price, m.manufacturers_name from :table_products p left join :table_product_attributes pa on (if(p.parent_id is null, p.products_id = pa.products_id, p.parent_id = pa.products_id)) left join :table_templates_boxes tb on (pa.id = tb.id and tb.code = "Manufacturers" and tb.modules_group = "ProductAttribute") left join :table_manufacturers m on (pa.value = m.manufacturers_id), :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 = 1 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(':default_flag', 1);
$Qlisting->bindInt(':language_id', $OSCOM_Language->getID());
@@ -94,10 +94,10 @@ function execute() {
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);
}
@@ -108,7 +108,7 @@ function execute() {
$Qlisting->bindInt(':manufacturers_id', $this->_manufacturer);
}
- $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');
Please sign in to comment.
Something went wrong with that request. Please try again.