*

felix891

  • **
  • 8 posts
How to add filter to search sidebar
« on: October 16, 2024, 02:10:23 PM »
Good morning everyone. I'm working with the latest version of osclass and the Sigma theme. I'm making a small change to the search sidebar to add a filter (in addition to the existing one that only shows ads with photos), to only show ads that have a phone number.
I then added the checkbox and created a simple plugin that uses the search conditions hook. Questo il codice che ho inserito nel plugin:

Code: [Select]
<?php
/*
 Plugin Name: Filter Listings with Phone
 Description: Adds a filter to only display ads with a phone number
 Author: Me
 Version: 1.0
*/

osc_add_hook('search_conditions''filter_with_phone_search_conditions');

function 
filter_with_phone_search_conditions($params) {

    if (
Params::getParam('bPhone') == 1) {

        
$params['where'] .= " AND " DB_TABLE_PREFIX "t_item.s_contact_phone IS NOT NULL AND " DB_TABLE_PREFIX "t_item.s_contact_phone != ''";
    } 
    return 
$params;
}
?>


Unfortunately this plugin doesn't seem to give the desired effect. Can any of you help me?
« Last Edit: October 16, 2024, 02:29:39 PM by felix891 »

*

mwindey

  • *****
  • 484 posts
Re: How to add filter to search sidebar
« Reply #1 on: October 22, 2024, 06:52:32 PM »
Quick try but it might work.... Not tested

Code: [Select]
osc_add_hook('search_conditions', 'filter_with_phone_search_conditions');

function filter_with_phone_search_conditions($params) {
    if (Params::getParam('bPhone') == 1) {
        $phoneCondition = DB_TABLE_PREFIX . "t_item.s_contact_phone IS NOT NULL AND " . DB_TABLE_PREFIX . "t_item.s_contact_phone != ''";
       
        if (isset($params['where']) && trim($params['where']) != '') {
            $params['where'] .= " AND " . $phoneCondition;
        } else {
            $params['where'] = $phoneCondition;
        }
    }
    return $params;
}

*

MB Themes

Re: How to add filter to search sidebar
« Reply #2 on: October 23, 2024, 04:34:37 PM »
I recommend to use class function:

Code: [Select]
function filter_with_phone_search_conditions() {
  Search::newInstance()->addConditions(DB_TABLE_PREFIX . "t_item.s_contact_phone IS NOT NULL AND " . DB_TABLE_PREFIX . "t_item.s_contact_phone != ''");
}

osc_add_hook('search_conditions', 'filter_with_phone_search_conditions');
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots