Post by phpuk » Sun Apr 26, 2009 5:29 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

Post by tommix » Sun Apr 26, 2009 8:28 am

Thanks :)

Active Member

Posts

Joined
Mon Apr 20, 2009 5:21 am

Post by halalan » Sat May 02, 2009 11:03 pm

I think having both options that can be turned on or off for the site would be great to have. My!! solution originally was to just change the HEADING title from Best Seller to Popular !! (it was the easy way)

Helping Each Other With Knowledge....
WHPOA.NET CTOA.NET CEMETERYTN.COM


User avatar
New member

Posts

Joined
Sat Mar 28, 2009 3:13 am
Location - U.S.A.
Who is online

Users browsing this forum: No registered users and 11 guests