Post by koc2018 » Fri Dec 14, 2018 1:09 pm

Does anyone know if there is a way to specify the sort order for featured products?
If not, in the source code, where is the code that actually fetch the featured products from database? (maybe I can simply add a sort by there to sort it?)

Thanks!

New member

Posts

Joined
Mon Oct 01, 2018 1:45 pm

Post by paulfeakins » Fri Dec 14, 2018 6:38 pm

In /catalog/controller/extension/module/featured.php

Add something like:
http://screenshots.antropy.co.uk/8635c3 ... 510812.jpg

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by koc2018 » Fri Dec 21, 2018 3:07 pm

Somehow adding the said line does not work for me:

Code: Select all

    'sort'        => 'name'
    
I saw this line early:

Code: Select all

    $products = array_slice($setting['product'], 0, (int)$setting['limit']);
    
Do we know where does

Code: Select all

$setting['product'] 
come from? (maybe I can change the value there instead?)

Thank you!
Last edited by straightlight on Sun Apr 12, 2020 11:09 pm, edited 2 times in total.
Reason: Added code tags.

New member

Posts

Joined
Mon Oct 01, 2018 1:45 pm

Post by koc2018 » Fri Dec 21, 2018 3:13 pm

Actually I found this works for me:
In the said file, near end of it, add this to sort it:

Code: Select all

			usort($data['products'], function($a, $b) {
				return strcmp($a['name'], $b['name']);
			});
			
Last edited by straightlight on Sun Apr 12, 2020 11:10 pm, edited 1 time in total.
Reason: Added code tags.

New member

Posts

Joined
Mon Oct 01, 2018 1:45 pm

Post by DS4A » Sun Apr 12, 2020 9:06 pm

I was looking for a quick solution to this issue myself.
The option I chose was to directly edit the order in the underlying data table of the database.
**!Ensure you backup your database before editing any table data!!** - You have been warned.

db - table
db > db_module

You can simply edit the order of the displayed product id's. You need the record where 'code' = 'featured'

You'll end up looking at something similar to the below JSON string:

Code: Select all

{"name":"Home Page","product_name":"","product":["263","1492","1400","1402","1454","1469","1466","1421","342"],"limit":"12","width":"125","height":"175","status":"1"}
the numbers string after 'product' is a list of the items to be displayed and in the order in which they are shown. Simply amend the order. Use your own preferred method e.g SQL statement, phpmyadmin etc.
This requires no edits to core OC files.
Last edited by straightlight on Sun Apr 12, 2020 11:11 pm, edited 1 time in total.
Reason: Removed constant caps and added code tags.

Newbie

Posts

Joined
Sun Apr 12, 2020 8:52 pm

Post by Sawyer77 » Sun May 23, 2021 8:10 pm

DS4A wrote:
Sun Apr 12, 2020 9:06 pm
I was looking for a quick solution to this issue myself.
The option I chose was to directly edit the order in the underlying data table of the database.
**!Ensure you backup your database before editing any table data!!** - You have been warned.

db - table
db > db_module

You can simply edit the order of the displayed product id's. You need the record where 'code' = 'featured'

You'll end up looking at something similar to the below JSON string:

Code: Select all

{"name":"Home Page","product_name":"","product":["263","1492","1400","1402","1454","1469","1466","1421","342"],"limit":"12","width":"125","height":"175","status":"1"}
the numbers string after 'product' is a list of the items to be displayed and in the order in which they are shown. Simply amend the order. Use your own preferred method e.g SQL statement, phpmyadmin etc.
This requires no edits to core OC files.
Thanks for the info, was a easy and smooth solution ::)
Works nice on my v3.0.3.7 shop

Illustrator and Photoshop Expert - Knowledge in Html, CSS and Bootstrap, not very good at programing. Had plenty of years experience in Prestashop, but went over to Opencart :)


Newbie

Posts

Joined
Sun May 09, 2021 11:09 am
Location - Sweden
Who is online

Users browsing this forum: Bing [Bot], JessiesBoutique, pprmkr and 514 guests