[FIXED] Bug in v8.3.0: Admin Search by Item ID Not Working
Hello everyone,
I'm writing to share a bug I've found after upgrading from Osclass 8.2.1 to 8.3.0, along with a working solution.
The Problem
On the admin dashboard, under Manage Listings, the filter to search for a listing by its specific Item ID no longer works in version 8.3.0.
In version 8.2.1: Searching for an Item ID (e.g., 1) correctly finds and displays the corresponding listing.
In version 8.3.0: The same search results in "No data available in table," even though the listing exists. A key detail is the message "Showing 0 to 0 of 0 results (filtered from 1 total results)," which confirms the system finds the item but incorrectly filters it out.
Root Cause Analysis
After comparing the core files between the two versions, the issue is located in the _makeSQL() function within the following file:
oc-includes/osclass/model/Search.php
In version 8.2.1, a search by Item ID was treated as a special case, bypassing all other default filters (e.g., b_active, b_enabled, etc.). This is the correct behavior.
In version 8.3.0, the logic was changed. Now, when searching by Item ID, the system also applies the default filters. If the listing you are searching for does not meet one of these other conditions (for instance, if it's inactive or blocked), the search will fail and return an empty result.
The Solution
The fix involves restoring the correct search logic from version 8.2.1. By making a small change to the Search.php file, we can ensure that an Item ID search is prioritized and executed correctly.
Warning: Always create a backup of your files before making any code changes.
Open the file:
oc-includes/osclass/model/Search.php
Locate the _makeSQL() function (around line 1215).
Find the following block of code:
PHP
$sql = '';
if($count) {
$this->dao->select('count(DISTINCT ' . DB_TABLE_PREFIX . 't_item.pk_i_id) as count');
} else {
$this->dao->select(sprintf('%st_item.*, %st_item.s_contact_name as s_user_name', DB_TABLE_PREFIX, DB_TABLE_PREFIX));
if($extraFields != '') {
$this->dao->select($extraFields); // plugins and extra columns in select
}
}
$this->dao->from(sprintf('%st_item', DB_TABLE_PREFIX));
// Search by item ID
if($this->withItemId) {
$this->dao->where('pk_i_id', (int)$this->itemId);
} else {
// ... the rest of the function continues here
Replace the entire block above with the corrected code below. This new code checks for an Item ID search first and handles it separately, just like in version 8.2.1.
PHP
$sql = '';
if($this->withItemId) {
// add field s_user_name
$this->dao->select(sprintf('%st_item.*, %st_item.s_contact_name as s_user_name', DB_TABLE_PREFIX, DB_TABLE_PREFIX));
$this->dao->from(sprintf('%st_item', DB_TABLE_PREFIX));
$this->dao->where('pk_i_id', (int)$this->itemId);
} else {
if($count) {
$this->dao->select('count(DISTINCT ' . DB_TABLE_PREFIX . 't_item.pk_i_id) as count');
} else {
$this->dao->select(DB_TABLE_PREFIX.'t_item.*, '.DB_TABLE_PREFIX.'t_item.s_contact_name as s_user_name');
if($extraFields != '') {
$this->dao->select($extraFields); // plugins!
}
}
$this->dao->from(DB_TABLE_PREFIX.'t_item');
// ... the rest of the function continues here
Save the file and upload it back to your server.
This change has fixed the issue on my installation, and the Item ID search now works perfectly.
I hope this solution is helpful for the community and that the developers can incorporate a permanent fix in the next official release.
Best regards.