Post by mschlem » Wed Sep 11, 2019 4:33 am

Hi community,

I am searching for a way to customize the php of the common template to define that the search of products sorts the item list by several fields.
in catalog / model / catalog / product.php

} else {
//$sql .= " ORDER BY p.sort_order";
$sql .= " ORDER BY case when p.price = 0 then 1 else 0 end, p.model";

But it does not change the sort order.
Thank you for your help.
Michael

Newbie

Posts

Joined
Wed Sep 11, 2019 4:22 am

Post by thekrotek » Wed Sep 11, 2019 8:02 am

If you want to simply order by different fields, then list these fields in desired order:

ORDER BY p.price, p.model, p.name

And so on.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by mschlem » Wed Sep 11, 2019 1:10 pm

Hi thank you very much for your feedback,
the final result should be
- Brand by sort order
- If the item has a price yes or no (yes on top) - but not sorted by price only is having a price
- Make
As brand is not available in the standard code I tried to first use the fields that are available but it seems my code is wrong or the place I located to change the code is wrong because nothing changed... in sql it is working like a charm :)

Thank you for your support.

Newbie

Posts

Joined
Wed Sep 11, 2019 4:22 am

Post by letxobnav » Wed Sep 11, 2019 1:37 pm

ORDER BY p.price=0, p.model

Crystal Light Centrum Taiwan
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by mschlem » Wed Sep 11, 2019 2:04 pm

Thanks for that hint, but is the php file and the line correct?
Also after refresh in backend there is no change in sort order in my search.

Newbie

Posts

Joined
Wed Sep 11, 2019 4:22 am

Post by letxobnav » Wed Sep 11, 2019 5:16 pm

not sure what you are refreshing.

In my experience, when system results are not what you expect, it is mostly down to the fact that the system is not executing what you think it is executing.
So check what the query actually looks like by adding

Code: Select all

$this->log->write($sql);
before

Code: Select all

$query = $this->db->query($sql);

Crystal Light Centrum Taiwan
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by paulfeakins » Wed Sep 11, 2019 5:38 pm

letxobnav wrote:
Wed Sep 11, 2019 5:16 pm
In my experience, when system results are not what you expect, it is mostly down to the fact that the system is not executing what you think it is executing.
Often the case, always do a sanity check to make sure you're actually in the right file.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by mschlem » Wed Sep 11, 2019 6:47 pm

Hi thank you for all the advises, I try to follow that up and take a look at the query.
Regarding the file, I try to manipulate the search results....

is
catalog / model / catalog / product.php
the correct file?
Thank you.

Newbie

Posts

Joined
Wed Sep 11, 2019 4:22 am

Post by letxobnav » Wed Sep 11, 2019 7:31 pm

yes.

there are two functions:
getProducts
getTotalProducts

those two you have to keep in sync wgt the select conditions, not wgt sorting etc. as that does not apply to the totals

Crystal Light Centrum Taiwan
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by mschlem » Thu Sep 12, 2019 4:17 am

Dear all thank you for your help so far. I am sorry but I did not get it managed.... I tried to echo $sql but the sort order is not what the sql is showing up.
Can you please help me.
Thank you

Newbie

Posts

Joined
Wed Sep 11, 2019 4:22 am

Post by mschlem » Thu Sep 12, 2019 8:57 pm

I've found a solution. The ajax filter extension was overriding the query. I had to adjust also the following methods. Now everthing works fine. Thanks to all of you!

\catalog\model\extension\module\d_ajax_filter.php
prepareAjaxFilter
prepareTable

Newbie

Posts

Joined
Wed Sep 11, 2019 4:22 am
Who is online

Users browsing this forum: No registered users and 25 guests