Page 1 of 1

Change default sort order in Product Listings ?

Posted: Sun Mar 31, 2024 1:36 am
by Phil
Is there a way to change the default sort order in product listings? Seems there is nothing in the admin panel, the default sort is by "Name" and I'd like to change it to "Model", how to approach that, what files should I look at?

I already have a custom template set and looking at product_listing.php in there, I can see the "Sort By " dropdown html, just can't seem to find the default sort to modify?

I would also like to change the default sort in the admin area product listing, but that's less important.

Thanks in advance for any pointers.

Re: Change default sort order in Product Listings ?

Posted: Sun Mar 31, 2024 5:47 am
by heatherbell
This add-on enables setting a default sort order (as well as a lot more) - app.php/addons/paid_addon/zipur_product_manager/
Another option for setting a default sort order - viewtopic.php?f=28&t=1624&p=11290#p11290
Otherwise a change to core file - https://github.com/CE-PhoenixCart/Phoen ... ns.php#L14
Enable Sort Option: Model in Admin Dashboard>Configuration>Product Listing
Change PRODUCT_LIST_NAME to PRODUCT_LIST_MODEL in the line in the file linked above.
Of course, make a note in your ChangeLog of that core file change in case that file is overwritten in a future update.

Re: Change default sort order in Product Listings ?

Posted: Sun Mar 31, 2024 3:24 pm
by Phil
Thank you for the quick and detailed answer. That addon seems too elaborate for my needs. The second link is not visible to me (no access to VIP I suppose). Modifying the core file worked, thanks for pointing me in the right direction!!

What about the Admin panel "Categories/Products" default sort by model instead of name? Still can't find how to modify that.

Re: Change default sort order in Product Listings ?

Posted: Mon Apr 01, 2024 11:32 am
by heatherbell
Phil wrote: Sun Mar 31, 2024 3:24 pm The second link is not visible to me (no access to VIP I suppose).
That is a Hook Addon which changes behaviour without changing core files. There's a lot of addons and code help available to PRO VIP members which makes membership well worth it. GO PRO
Phil wrote: Sun Mar 31, 2024 3:24 pm What about the Admin panel "Categories/Products" default sort by model instead of name? Still can't find how to modify that.
So, looking at /admin/catalog.php https://github.com/CE-PhoenixCart/Phoen ... og.php#L32 shows a require for /includes/segments/process_action.php. A lot of the logic for Admin pages is handled by files in /admin/includes/actions/.
So looking there, /admin/includes/actions/catalog/ can be seen which leads to finding https://github.com/CE-PhoenixCart/Phoen ... #L107-L109 where 2 instances of ORDER BY pd.products_name can be seen. That orders the database query result set by the data in the products_name column of the product_description pd table, ascending by default.
Changing pd.products_name accordingly to the table and column you desire would probably change the sort. If sort by model was your intention, for example, change both instances to p.products_model.
Probably a Hook Addon could be made to do the same thing without changing core code which would be a better solution.
Caveat that the above is just guesswork after taking the time to research your question.

Generally, if a post provides a working answer, the Thumbs Up icon button in the post should be used to indicate to future readers that it works.
Of course, if someone's time saves your time or helps to develop your store then the Buy Me A Beverage button is also an option :)

Re: Change default sort order in Product Listings ?

Posted: Mon Apr 01, 2024 1:12 pm
by Phil
Thank you for the pointers again, modifying that query actually works :) (beverage on the way, heh)