Post by Vindojeens » Thu Jul 13, 2017 5:48 pm

Hello :D

I wanted to know how to change the default sort order of related products on the product page?
By default the product with the lowest product id is displayed first, and the one with the highest last.

I want to revert it, so the related product with the highest product id (the newest product) gets displayed first and the one with the lowest product id (the oldest product) last.

Is this possible?

Thanks a lot in advance!

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by DigitCart » Thu Jul 13, 2017 6:16 pm

Yes, It's possible.

you must edit this file:

Code: Select all

catalog/model/catalog/product.php
Find:

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
Change it to:

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC");
As you see above I've added ORDER BY p.date_added DESC to the end of the query.

Tested with Opencart 2.3.0.2

My Extensions / DigitCart


User avatar
Active Member
Online

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by Vindojeens » Thu Jul 13, 2017 10:32 pm

Thank you, this works great, you really helped me! :)

Newbie

Posts

Joined
Sun Nov 20, 2016 12:49 am

Post by DigitCart » Thu Jul 13, 2017 10:43 pm

Vindojeens wrote:
Thu Jul 13, 2017 10:32 pm
Thank you, this works great, you really helped me! :)
You're welcome. glad to hear it.

My Extensions / DigitCart


User avatar
Active Member
Online

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by Ilke » Wed Jul 19, 2017 3:29 pm

Hi Vindojeens!

Hope you’re doing well. I see that a great advise has already been shared on this topic. I can also look at your needs from a different perspective.
The related products provides an easy to use interface, that's for sure! But I assume that shouldn’t be all you offer to your customers. I believe a fully-fledged personalization app, such as Perzonalization - https://www.opencart.com/index.php?rou ... _id=26012 is indeed what you need.

With the help of Perzonalization you’ll be able to;
  • Showcase popular products, Products viewed by similar shoppers or Recent products
    Show custom recommendations where you choose which set of categories, colors etc. will be displayed
    Display recommendation widgets on home, cart, product, search no results, collection pages
    Place personalized recommendation on your e-mail templates
Give it a 14 day free trial - www.perzonalization.com/start-free-tria ... -opencart/ - and let me know what you think!

Best of luck

Ilke Karabogali

Disclaimer: I am the co-founder of Perzonalization - www.perzonalization.com - a predictive personalization SaaS solution which is used by eCommerce websites.

Newbie

Posts

Joined
Fri May 26, 2017 2:20 am
Who is online

Users browsing this forum: No registered users and 26 guests