Post by radact » Thu Feb 22, 2024 7:40 pm

Using 2.3.0.2

When selecting a category to display the products, it currently it goes to "Rating: Highest" automatically. Not sure why it's selecting that instead of "Default"!

Is "Rating: Highest" set somewhere? Is there an easy fix to revert it back to "Default" instead?

Thanks in advance.

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by ADD Creative » Thu Feb 22, 2024 11:17 pm

The default sort order is hard code. Is your theme or any extensions changing it?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Thu Feb 22, 2024 11:35 pm

radact wrote:
Thu Feb 22, 2024 7:40 pm
Is "Rating: Highest" set somewhere?
Probably in your cookies?

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


User avatar
Legendary Member

Posts

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

Post by radact » Fri Feb 23, 2024 7:06 am

ADD Creative wrote:
Thu Feb 22, 2024 11:17 pm
The default sort order is hard code. Is your theme or any extensions changing it?
The only additional information I can provide is that I just found out that my host has decided to upgrade their version of SQL to v8 and have told me that OC2.3.0.2 was previously using SQL v5.7, and may no longer be fully compatible. If manually change from the dropdown to Default, it works fine. However if I change it from NAME (A-Z), I get the following error that is attributed to the change in the SQL version.

Code: Select all

Fatal error: Uncaught Exception: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY LCASE(pd.name) ASC, LCASE(pd.name) ASC LIMIT 0,20' at line 1<br />Error No: 1064<br />SELECT p.product_id, (SELECT AVG(rating) AS total FROM oc_review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT price FROM oc_product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '1' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM oc_product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '1' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special FROM o in /home/anoth305/public_html/shop/system/library/db/mysqli.php on line 40
Upgrading to OC 3 or 4 is out of the question at this point in time due to several extensions that I rely on are have not been upgraded so I need to keep the status quo.

The only other solution that I can think of is a VQMOD that can rewrite the syntax to prevent the above error, to make it compatible with SQL 8. Unfortunately that is out of my technical area. Any ideas?
Last edited by radact on Fri Feb 23, 2024 7:11 am, edited 2 times in total.

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by radact » Fri Feb 23, 2024 7:08 am

Probably in your cookies?
Not likely, it does it for each new category that I select, even ones I have previously not opened. It seems to be defaulting to "Rating: Highest".

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by ADD Creative » Fri Feb 23, 2024 8:01 am

Could be you have something modifying your SQL query. The error seems to have "LCASE(pd.name) ASC" twice. Although that just could be the way the error was formatted.

For MySQL 8 you may have to remove NO_ZERO_DATE from the sql_mode.

Try making it the same as this line.
https://github.com/opencart/opencart/bl ... li.php#L18

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by radact » Fri Feb 23, 2024 11:27 am

ADD Creative wrote:
Fri Feb 23, 2024 8:01 am
Could be you have something modifying your SQL query. The error seems to have "LCASE(pd.name) ASC" twice. Although that just could be the way the error was formatted.

For MySQL 8 you may have to remove NO_ZERO_DATE from the sql_mode.

Try making it the same as this line.
https://github.com/opencart/opencart/bl ... li.php#L18
I can't do that sorry, I have ZERO experience with SQL stuff, I don't want to screw anything up further. I think it's just barely hanging on since they upgraded to the new version of SQL 8.

Ideally a xml mod that changes the default sort criteria to Default rather than Rating would be ok. I can work with that, but no idea where in the code Rating is hard wired to be the default.

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by radact » Fri Feb 23, 2024 1:50 pm

I tried this free extension, but it doesn't seem to make any difference:
https://www.opencart.com/index.php?rout ... _license=0

There is also this extension which promises to fix the problem, looks more promising, but won't know until I purchase it:
https://www.opencart.com/index.php?rout ... rt%20order

Hoping there's another solution.

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by ADD Creative » Fri Feb 23, 2024 5:42 pm

There are two places where the default sort order is set.

First in catalog/controller/product/category.php line 21.
https://github.com/opencart/opencart/bl ... ry.php#L21

Then in catalog/model/catalog/product.php line 177.
https://github.com/opencart/opencart/bl ... t.php#L177

Both are hard coded to 'p.sort_order'. Check you files are the same. Also check for the same files under system/storage/modification.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by radact » Fri Feb 23, 2024 8:10 pm

Both are hard coded to 'p.sort_order'. Check you files are the same. Also check for the same files under system/storage/modification.
I changed it to:

Code: Select all

$sort = 'pd.name';
but I get the same error message, so obviously it's trying to sort by name but the query syntax is wrong.

What is the variable I should be using to force it to use 'Default', because that seems to work fine. If I select 'Default' from the dropdown menu, it sorts them alphabetically but doesn't come up with the error. The error occurs if I specifically choose 'Name (A-Z)' or 'Name (Z-A)'

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by paulfeakins » Fri Feb 23, 2024 8:31 pm

radact wrote:
Fri Feb 23, 2024 1:50 pm
There is also this extension which promises to fix the problem, looks more promising, but won't know until I purchase it:
https://www.opencart.com/index.php?rout ... rt%20order

Hoping there's another solution.
Purchase it and get a refund if it doesn't fix?

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


User avatar
Legendary Member

Posts

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

Post by ADD Creative » Sat Feb 24, 2024 12:31 am

'p.sort_order' is the value for default. You can see in the code at.
https://github.com/opencart/opencart/bl ... #L240-L241

It looks like you have an theme, extension or modification that is changing the default OpenCart sorting.

Try using the default theme, disable extension/modifications one by one and compare your files against a clean download.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by koku » Mon Feb 26, 2024 7:42 pm

There is also this extension which promises to fix the problem, looks more promising, but won't know until I purchase it:
https://www.opencart.com/index.php?rout ... rt%20order

I am the developer of the extension. We dont promise to fix issues/bugs that may have created by another extension or hardcoded things. The extension works on a default OC installation and in most cases even on modified OpenCart installations but we cannot promise that will do the job and resolve a bug or so. The purpose of the extension is to define different sort order (than the default).

I suggest to fix any issue first and then purchase the extension if you want to change the sort order.

Easy Multi-Store Extension
ACS Courier Vouchers for OpenCart 2, 3 & 4
Skroutz Smart Cart (Έξυπνο καλάθι) for OpenCart
Έλεγχος Εγκυρότητας Ελληνικού ΑΦΜ για OpenCart
Change the style of your OpenCart admin dashboard for free!


Active Member

Posts

Joined
Thu Feb 14, 2013 2:28 am

Post by paulfeakins » Tue Feb 27, 2024 7:03 pm

koku wrote:
Mon Feb 26, 2024 7:42 pm
I am the developer of the extension. We dont promise to fix issues/bugs that may have created by another extension or hardcoded things.
We often allow customers to try our extensions and get a refund if there is a conflict.

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


User avatar
Legendary Member

Posts

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

Post by SohBH » Tue Feb 27, 2024 7:42 pm

The error message indicates ORDER BY repeated 2 times. This does not happen in default installation and can be fixed by undo whatever changes is made.

View all extensions | Request custom work | Pricing | Contact Me


User avatar
Active Member

Posts

Joined
Mon Nov 02, 2020 12:01 am
Location - Malaysia

Post by koku » Tue Feb 27, 2024 7:59 pm

paulfeakins wrote:
Tue Feb 27, 2024 7:03 pm
We often allow customers to try our extensions and get a refund if there is a conflict.
Of course and in most cases we resolve the conflicts. But in this case it was asked if the extension will fix a problem/bug in the installation.

In this case, my advice is that any bug in the current installation should be fixed (not with an extension) anyway before trying to modify the default behaviour using any extension.

Easy Multi-Store Extension
ACS Courier Vouchers for OpenCart 2, 3 & 4
Skroutz Smart Cart (Έξυπνο καλάθι) for OpenCart
Έλεγχος Εγκυρότητας Ελληνικού ΑΦΜ για OpenCart
Change the style of your OpenCart admin dashboard for free!


Active Member

Posts

Joined
Thu Feb 14, 2013 2:28 am

Post by radact » Tue Feb 27, 2024 8:07 pm

Ok, I've managed to fix it to come up with Default again instead of Rating.
However the error still remains when selecting Name A-Z or Name Z-A. All the other options such as Rating, Price etc all seem to work fine.

Code: Select all

Fatal error: Uncaught Exception: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY LCASE(pd.name) DESC, LCASE(pd.name) DESC LIMIT 0,20' at line 1<br />Error No: 1064<br />SELECT p.product_id, (SELECT AVG(rating) AS total FROM oc_review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT price FROM oc_product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '1' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM oc_product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '1' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special FROM in /home/anoth305/public_html/shop/system/library/db/mysqli.php on line 40
Since I posted this error, my host has moved my site onto an older server which still supports SQL5.7, so it should have returned to normal. It looks like the version of SQL is not the cause then.

It's not a deal breaker, because technically, "Default" is "NAME A-Z", so it operates correctly. The error message only occurs when you actually select "NAME A-Z" from the dropdown menu. Now I am stumped again.

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by radact » Tue Feb 27, 2024 8:40 pm

ADD Creative wrote:
Fri Feb 23, 2024 8:01 am
Could be you have something modifying your SQL query. The error seems to have "LCASE(pd.name) ASC" twice. Although that just could be the way the error was formatted.

For MySQL 8 you may have to remove NO_ZERO_DATE from the sql_mode.

Try making it the same as this line.
https://github.com/opencart/opencart/bl ... li.php#L18
I tried your suggestion, no change. Here is my modified mysqli.php file:

Code: Select all

<?php
namespace DB;
final class MySQLi {
	private $connection;

	public function __construct($hostname, $username, $password, $database, $port = '3306') {
		$this->connection = new \mysqli($hostname, $username, $password, $database, $port);

		if ($this->connection->connect_error) {
			throw new \Exception('Error: ' . $this->connection->error . '<br />Error No: ' . $this->connection->errno);
		}

		$this->connection->set_charset("utf8");
		$this->connection->query("SET SQL_MODE = 'NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION'") ;
	}

	public function query($sql) {
		$query = $this->connection->query($sql);

		if (!$this->connection->errno) {
			if ($query instanceof \mysqli_result) {
				$data = array();

				while ($row = $query->fetch_assoc()) {
					$data[] = $row;
				}

				$result = new \stdClass();
				$result->num_rows = $query->num_rows;
				$result->row = isset($data[0]) ? $data[0] : array();
				$result->rows = $data;

				$query->close();

				return $result;
			} else {
				return true;
			}
		} else {
			throw new \Exception('Error: ' . $this->connection->error  . '<br />Error No: ' . $this->connection->errno . '<br />' . $sql);
		}
	}

	public function escape($value) {
		return $this->connection->real_escape_string($value);
	}
	
	public function countAffected() {
		return $this->connection->affected_rows;
	}

	public function getLastId() {
		return $this->connection->insert_id;
	}
	
	public function connected() {
		return $this->connection->ping();
	}
	
	public function __destruct() {
		$this->connection->close();
	}
}

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am

Post by ADD Creative » Wed Feb 28, 2024 5:36 pm

Find your catalog/model/catalog/product.php file. Also look for a system/storage/modification/catalog/model/catalog/product.php file.

Compare these two files against a clean version of that file from a clean download or from the following link.
https://github.com/opencart/opencart/bl ... roduct.php

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by radact » Wed Feb 28, 2024 8:08 pm

ADD Creative wrote:
Wed Feb 28, 2024 5:36 pm
Find your catalog/model/catalog/product.php file. Also look for a system/storage/modification/catalog/model/catalog/product.php file.

Compare these two files against a clean version of that file from a clean download or from the following link.
https://github.com/opencart/opencart/bl ... roduct.php
Well that was bizarre! I looked in that folder and this is what I found:
Image
Looks like this other product.php file was created nearly 4 years ago, by what, I have no idea. So switched it around to the .old file, which looks to be intact, and it seems to have now fixed the problem! NAME A-Z and NAME Z-A works again!

Maybe the problem has been there for a long time and I never noticed it before. I'm glad it's back to 100% again. So far I haven't noticed any other functionality issues as a result of reverting back to the original.

Thank you so much for everyone for pointing me in the right direction. :-)

New member

Posts

Joined
Fri Nov 25, 2016 11:36 am
Who is online

Users browsing this forum: No registered users and 11 guests