Post
by tomlatham » Tue Oct 26, 2010 10:36 am
Okay, I haven't figured out how to get SPECIFIC products in the Latest Products module, but I found out how to show products based on other criteria and to reverse sort when needed.
In >> catalog >> model >> catalog >> product.php
FIND:
public function getLatestProducts($limit) {
$product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit);
if (!$product_data) {
$query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating 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) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE 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') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
CHANGE:
ORDER BY p.date_added DESC LIMIT " . (int)$limit);
TO:
ORDER BY p.price DESC LIMIT " . (int)$limit);
This is if you want it to be listed by price.
OTHER SORTING:
Sort by product name = pd.name
Sort by product id (generated by MySQL) = p.product_id
Sort by rating = rating
etc.
TO REVERSE THE ORDER OF ANYTHING:
In the same "getLatestProducts()" function:
Find: DESC
Change to: ASC
Always delete the "cache.product.latest..." file in the system/cache folder after making these changes.