Post by bizbey » Thu May 27, 2010 11:40 pm

I've been trying to sort the latest products on the frontpage without much luck.
At first it looked like the products are sorted by "model" because it was arranged alphabetically by model name. I changed the modelname of a few products but there was no change in display.
I then tried to change the "date available", the ones i wanted to be displayed on top as being the newest in date but that didn't have any effect as well.

Can anyone please tell me in what way the latest products are sorted on the frontpage? ???

Thanks

Newbie

Posts

Joined
Thu May 27, 2010 11:34 pm

Post by bizbey » Fri May 28, 2010 3:19 pm

Anyone? I'm almost finished with my store, this is the last problem i have to fix!

Newbie

Posts

Joined
Thu May 27, 2010 11:34 pm

Post by unknownmale » Fri May 28, 2010 11:21 pm

Maybe i am miss understanding you but arnt they sorted in order in which they were added to the database.

It can be changed quiet easily to sort in assending or decending order. But not sure what you actually want it to do.

New member

Posts

Joined
Fri May 21, 2010 8:39 pm

Post by bizbey » Sat May 29, 2010 4:07 pm

I'm trying to sort it manually. For example product 1 on place 2, product 2 on place 1, product 3 on place 5 etc.

Newbie

Posts

Joined
Thu May 27, 2010 11:34 pm

Post by rock304 » Mon May 31, 2010 12:04 am

Hmm--I thought this was going to be added in 1.4.8 and I do not see it here unless I am missing something

http://www.opencart.com/index.php?route ... &blog_id=9

New member

Posts

Joined
Tue Mar 23, 2010 9:38 pm

Post by bizbey » Fri Jun 04, 2010 3:24 pm

I went through that list but i can't find it.

Is there a manual fix to sort the latest products the way i want it to be sorted?

If unknownmale is right and the products are shown in order they are added to the database, i was thinking about changing that date manually. Is that possible or will it screw up some things?

Newbie

Posts

Joined
Thu May 27, 2010 11:34 pm

Post by fido-x » Fri Jun 04, 2010 3:43 pm

Latest products are sorted by date added in reverse chronological order. In other words, the most recent addition appears at position 1, the next most recent at position 2, etc. They are sorted that way because they are the latest products you have added to your store. You can change the sort order by editing the model (catalog/model/catalog/product.php). Find the "getLatestProducts($limit)" function (around line 284) and change the "ORDER BY" bit at the end of the query (line 288) to what you want.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Fri Jun 04, 2010 6:39 pm

1.4.8 never said it would have sorting of latest. That would not be "latest" then.
It does however allow you to change the position of all modules now. So you could put the featured products on the home page. Or make a new module called "sorted" and put that on the homepage

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by bizbey » Thu Jun 17, 2010 5:28 pm

Thanks for the suggestions. I finally managed to sort it by changing the "date added" in the mysql database.

Newbie

Posts

Joined
Thu May 27, 2010 11:34 pm

Post by moyger » Mon Jun 21, 2010 1:24 am

but you edited the database directly not through the admin CMS? Is there a way that you could administer it from there. Like really make the sort_order functionable coz I think it's not really working at all. Hope this could be resolved since a lot of people here want random stuff on the homepage. THanks!!!

Newbie

Posts

Joined
Wed Apr 28, 2010 1:55 am

Post by tomlatham » Tue Oct 26, 2010 8:57 am

I'm stuck on this too. I want specific products to show on the home page, not have them changing, otherwise it's confusing for the customers that come back to reorder (we're a supplier that sells the same product to the same customers routinely).

You can replace the "Latest Products" module with the "Featured Products" module in the center of the home page, but there's still no "sort order" for Featured Products, and in fact I can't even get products to show up in this module. I bailed on it.

The only solution I found is the Ordered Products List mod but it seems to only work with an older version than 1.4.9. (the code's not there to replace anymore) http://www.opencart.com/index.php?route ... order=DESC
Last edited by tomlatham on Tue Oct 26, 2010 10:37 am, edited 1 time in total.

Newbie

Posts

Joined
Thu Oct 21, 2010 9:54 am

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.

Newbie

Posts

Joined
Thu Oct 21, 2010 9:54 am

Post by broadsighted » Sat Dec 18, 2010 5:16 am

Thank you so much tomlatham, that did the trick.

Qphoria, I understand your reasoning behind no sort order for "Latest Products"...

Still, people like their options. :)

Image


Newbie

Posts

Joined
Tue Nov 30, 2010 4:27 am
Location - Denver, CO

Post by liquidgooey » Fri Jan 14, 2011 7:23 am

Tomlatham, thank you so much for doing this work...I just changed it to p.sort_order (cause that makes sense) and all is wonderful in my world!!

Newbie

Posts

Joined
Wed Sep 29, 2010 12:50 pm

Post by jeweller8 » Wed Mar 30, 2011 1:00 am

Thankyou for this solution. I thought it hadn't worked for me at first until I read that I should delete the cache file first! :)

white gold wedding rings


Newbie

Posts

Joined
Sat Mar 26, 2011 7:08 pm

Post by movingwifi » Fri May 13, 2011 1:49 am

Thanks for this Tomlatham.

Pointing me to catalog > model > catalog > product.php helped me get my Featured Products sorted using the Sort Order field on the admin page for each product.

in this product.php file for 1.4.9.5, line 367 is changed to:

$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_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.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.sort_order ASC LIMIT " . (int)$limit);

Gerry

Newbie

Posts

Joined
Fri May 06, 2011 7:40 pm

Post by lostinjapan » Mon Mar 12, 2012 1:36 am

Opencart Version 1.5.1.3

Hi, I made the modifications to catalog > model > catalog > product.php and cleared the cache, but nothing different happened.

$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_available DESC LIMIT " . (int)$limit);

I even tried changing the ORDER BY p.date_available2 just to see if it would throw an error...and it didn't.

Why is it not even reading the inside of
if (!$product_data) {

in the
public function getLatestProducts($limit) {
function?

The next thing I tried was to comment out the whole query and clear my cache...
and *nothing* bad happened. I got the exact same result as the time before.

Does this point to a theme overriding the system default query? That's....not expected, right? Has the file itself changed so I should change different lines?

I contacted the person who made the theme (Cartmania) and they said
Hello lostinjapan,
I am afraid it is not possible. The system automatically sorts the products by date added and it can’t be changed. At least not safely in terms of future updates and upgrades.

Any comments are appreciated

Newbie

Posts

Joined
Thu Sep 29, 2011 6:55 am

Post by lostinjapan » Mon Mar 12, 2012 2:07 am

Okay, our whole store depends on viewing products by date_available. This is because it is a video store and we are adding video titles out of order. Not knowing what else to do and knowing my store wasn't using the getLatestproducts function at all, I just hacked the sort order in:

public function getProducts($data = array()) {

Here is the code:

if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
} else if ($data['sort'] == 'p.quantity' || $data['sort'] == 'p.price' || $data['sort'] == 'rating' || $data['sort'] == 'p.sort_order') {
$sql .= " ORDER BY " . $data['sort'];
} else {
//$sql .= " ORDER BY " . $data['sort'];
$sql .= " ORDER BY p.date_available";
}

} else {
//$sql .= " ORDER BY p.sort_order";
$sql .= " ORDER BY p.date_available";
}

now it works.

Newbie

Posts

Joined
Thu Sep 29, 2011 6:55 am
Who is online

Users browsing this forum: No registered users and 23 guests