Post by phpuk » Sun Apr 26, 2009 5:37 am

Hi,

Currently the 'BESTSELLERS' side module displays it's results based on the most viewed products not the most sold products.

A number of people have asked for the module to be changed to reflect the most sold items.

Here is one solution:

Delete the cache.product.popular.... file from the cache folder.

Open the script: catalog/model/catalog/product.php

Go to line 143 and replace the getBestSellerProducts function with the following:

Code: Select all

	public function getBestSellerProducts($limit) {
		$product = $this->cache->get('product.popular.' . $this->language->getId() . '.' . $limit);

		if (!$product) {
            $prod_id = ' p.product_id IN( ';

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

    		$results = $query->rows;

    		foreach ($results as $result) {
                $prod_id .= $result['product_id'] . ',';
    		}

            $prod_id = substr($prod_id,0,strlen($prod_id)-1) . ') AND ';

 			$query = $this->db->query("SELECT * FROM product p LEFT JOIN product_description pd ON (p.product_id = pd.product_id) WHERE " . $prod_id . " p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->language->getId() . "' LIMIT " . (int)$limit);

			$temp = $query->rows;

            for($i = 0; $i < sizeof($temp); $i++) {
                $j = 0;
                while($results[$i]['product_id'] != $temp[$j]['product_id']){
                    $j++;
                }
                $product[$i] = $temp[$j];
            }

			$this->cache->set('product.popular.' . $this->language->getId() . '.' . $limit, $product);
		}

		return $product;
	}
Let me know if you have any problems.

Phil.

Global Moderator

Posts

Joined
Wed Mar 25, 2009 10:57 am
Who is online

Users browsing this forum: No registered users and 3 guests