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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.