Page 1 of 1

[1.2.9] [1.2.8] Bug in /catalog/model/catalog/product.php

Posted: Tue Jun 30, 2009 8:58 pm
by JNeuhoff
The following database queries in /catalog/model/catalog/product.php don't always match up in the number of products returned. This bug exists both in Opencart 1.2.8 and 1.2.9.
  • getProductsByCategoryId
    getTotalProductsByCategoryId
The 2 queries use different WHERE clauses. I suggest to fix the getTotalProductsByCategoryId by using the same WHERE-clause in there as in getProductsByCategoryId.

E.g. in Opencart 1.2.8 it would be something like this:

Code: Select all

	public function getTotalProductsByCategoryId($category_id = 0) {
		$sql = "SELECT COUNT(*) AS total FROM product_to_category p2c LEFT JOIN product p ON (p2c.product_id = p.product_id) LEFT JOIN stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND ss.language_id = '" . (int)$this->language->getId() . "' AND p2c.category_id = '" . (int)$category_id . "'";
		$query = $this->db->query( $sql );
		
		return $query->row['total'];
	}