Jump to content

display category bestseller/but not for subcategories


diasansley

Recommended Posts

using version opencart 1.4.9.12

hey guys i wanted to add the bestseller to be displayed per category below are a few

the problem is if i click on a sub category it "text error"  i placed this

$this->data['text_error'] = $this->language->get('text_error');

 

if i click on the category it displays me the correct result, its not workin on the subcategories

 

here is the query from the category controller

  
/*my query*/
   $results = $this->model_catalog_product->getBestSellerProductsSearch($this->config->get('bestseller_limit'),$category_id);

/*default query which is commented */
		//	$results = $this->model_catalog_product->getProductsByCategoryId($category_id, $sort, $order, ($page - 1) * $this->config->get('config_catalog_limit'), $this->config->get('config_catalog_limit'));

 

 

 

 

here is the function

	public function getBestSellerProductsSearch($limit,$category_id) {
	//$product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit);

	//if (!$product_data) { 
		$product_data = array();


		$query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE op.category_id = ".$category_id." AND o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit);

//		echo "test";
	//	exit();

		foreach ($query->rows as $result) {
			$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

			if ($product_query->num_rows) {
				$product_data[] = $product_query->row;
			}
		}

//		$this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data);
//	}

	return $product_data;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.