*

Ghiz

  • ***
  • 31 posts
Location filter
« on: February 21, 2018, 04:04:05 PM »
Hi
I notice when set a location city in search the ads showed are only from this city.


Is it possible to set to view the ads starting from the city selected then below view the ads from other city in sort by distance from close to far?

Regards
Ghislain.

*

MB Themes

Re: Location filter
« Reply #1 on: February 22, 2018, 09:57:50 AM »
@Ghiz

In theme files in functions.php after line:
function mb_filter_extend() {

add:
Code: [Select]
if(function_exists('radius_item_loc')) {
  Search::newInstance()->addJoinTable( DB_TABLE_PREFIX.'t_item_radius.item_id', DB_TABLE_PREFIX.'t_item_radius', DB_TABLE_PREFIX.'t_item.pk_i_id = '.DB_TABLE_PREFIX.'t_item_radius.item_id', 'LEFT OUTER' ) ;

  $cd = ModelRadius::newInstance()->getCordByCity(Params::getParam('city'));

  if(@$cd['latitude'] <> '' && @$cd['longitude'] <> '') {
    $sql = sprintf('SQRT(POWER(%st_item_radius.longitude - %d, 2) + POWER(%st_item_radius.latitude - %d, 2))', DB_TABLE_PREFIX, @$cd['longitude'], DB_TABLE_PREFIX, @$cd['latitude']);
 
    Search::newInstance()->order($sql . ' ASC, ' . DB_TABLE_PREFIX.'t_item.dt_pub_date DESC', '');
  }
}


I did not tested it, but at least you have way to do it ;)





  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ghiz

  • ***
  • 31 posts
Re: Location filter
« Reply #2 on: February 23, 2018, 12:14:42 PM »
Thank you MB-Theme for the answer

Sincerly i did tried it but unfortunately dosent make any difference so far.
I think this is a good point to add in an update.
Regards
Ghislain. ;)

*

MB Themes

Re: Location filter
« Reply #3 on: February 23, 2018, 01:52:46 PM »
@Ghiz
Have you entered some city into search that has coordinates in db?
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ghiz

  • ***
  • 31 posts
Re: Location filter
« Reply #4 on: February 23, 2018, 01:54:49 PM »
You maybe right i have only 3 ads i made for test when i will put productio online i will again test it when clients will ad more ads.
Cheers
Ghiz

*

Ghiz

  • ***
  • 31 posts
Re: Location filter
« Reply #5 on: February 23, 2018, 02:06:46 PM »
Maybe i did not seted it ok, i did set it under the theme extra data, Is it ok or maybe advise.
Regards
Ghiz.



Code: [Select]
function mb_filter_extend() {
  // THEME EXTRA DATA
  Search::newInstance()->addJoinTable( DB_TABLE_PREFIX.'t_item_stela.fk_i_item_id', DB_TABLE_PREFIX.'t_item_stela', DB_TABLE_PREFIX.'t_item.pk_i_id = '.DB_TABLE_PREFIX.'t_item_stela.fk_i_item_id', 'LEFT OUTER' ) ; // Mod
 
  if(function_exists('radius_item_loc')) {
  Search::newInstance()->addJoinTable( DB_TABLE_PREFIX.'t_item_radius.item_id', DB_TABLE_PREFIX.'t_item_radius', DB_TABLE_PREFIX.'t_item.pk_i_id = '.DB_TABLE_PREFIX.'t_item_radius.item_id', 'LEFT OUTER' ) ;

  $cd = ModelRadius::newInstance()->getCordByCity(Params::getParam('city'));

  if(@$cd['latitude'] <> '' && @$cd['longitude'] <> '') {
    $sql = sprintf('SQRT(POWER(%st_item_radius.longitude - %d, 2) + POWER(%st_item_radius.latitude - %d, 2))', DB_TABLE_PREFIX, @$cd['longitude'], DB_TABLE_PREFIX, @$cd['latitude']);
 
    Search::newInstance()->order($sql . ' ASC, ' . DB_TABLE_PREFIX.'t_item.dt_pub_date DESC', '');
  }
}

*

MB Themes

Re: Location filter
« Reply #6 on: February 23, 2018, 10:55:04 PM »
It is ok
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ghiz

  • ***
  • 31 posts
Re: Location filter
« Reply #7 on: February 24, 2018, 01:44:32 PM »
Thank you i will keep it as it is and will investigate ounce online .
Ghiz.

*

webcity

  • ****
  • 243 posts
Re: Location filter
« Reply #8 on: March 03, 2018, 05:25:10 AM »
Hi,

I'm also using this plugin.

I would like to show ads from surrounding areas too.

This classified site does it pretty well : https://www.freeads.co.uk/coalville/buy-sell/pets/dogs/#.WpoiMxNua7M

It shows the ads in the selected town/location then a message to show ads in surrounding region too.

I'm using the gum theme, where can I insert the code in the functions.php ?

Many thanks.

functions.php code:

Code: [Select]
require GUM_THEME_PATH . 'class/GumRegister.php';

$_GumWatchlist = new GumWatchlist();

require GUM_THEME_PATH . 'class/payments_pro/GumPaymentsPro.php';
$_GumPaymentsPro = new GumPaymentsPro();

function gum_meta_search($catId = null) {
    GumFieldForm::meta_fields_search($catId);
}
osc_remove_hook('search_form', 'osc_meta_search');
osc_add_hook('search_form', 'gum_meta_search');

osc_remove_hook('header', 'osc_meta_generator');

function cust_pattern_search_all_keywords_only($params) {
    if (@$params['sPattern'] != '') {
        $mSearch = Search::newInstance();
        $query_elements = (array) json_decode($mSearch->toJson());
        $pattern = $query_elements['sPattern'];

        foreach (explode(' ', $pattern) as $word) {
            $query_elements['sPattern'] = str_replace($word, '+' . $word, $query_elements['sPattern']);
        }

        $mSearch->addLocale('%');
        $mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');

        $mSearch->setJsonAlert($query_elements);       
    }
}

osc_add_hook('search_conditions', 'cust_pattern_search_all_keywords_only', 10);

function cust_alerts_user_dashboard() {
    if (Params::getParam('page') == "user" && Params::getParam('action') == "alerts") {
        $webUser = new CWebUser;

        $aAlerts = Alerts::newInstance()->findByUser( Session::newInstance()->_get('userId'), false );
        $user = User::newInstance()->findByPrimaryKey( Session::newInstance()->_get('userId'));
        foreach($aAlerts as $k => $a) {
            $array_conditions   = (array)json_decode($a['s_search']);

            $search = new Search();
            $search->setJsonAlert($array_conditions);
            if (osc_version() > 361) $search->notFromUser(Session::newInstance()->_get('userId'));
            $search->addLocale('%');
            $search->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
            $search->limit(0, 3);

            $aAlerts[$k]['items'] = $search->doSearch();
        }

        $webUser->_exportVariableToView('alerts', $aAlerts);
        View::newInstance()->_reset('alerts');
        $webUser->_exportVariableToView('user', $user);
    }
}

osc_add_hook('before_html', 'cust_alerts_user_dashboard');


osc_add_hook('init', function(){
    $aColors = array('red', 'blue', 'green', 'orange', 'dark');
    if(!OC_ADMIN && Params::getParam('color_theme') != '' && in_array(Params::getParam('color_theme'), $aColors)) {
        Session::newInstance()->_set('color_theme', Params::getParam('color_theme'));
        if($_SERVER['HTTP_REFERER']!='' && Params::getParam('preview')!='1') {
            if(preg_match('|'.osc_base_url().'|', $_SERVER['HTTP_REFERER'])) {
                osc_redirect_to($_SERVER['HTTP_REFERER']);
            }
        }
        osc_redirect_to(osc_base_url());
    }
});

*

MB Themes

Re: Location filter
« Reply #9 on: March 03, 2018, 09:18:41 AM »
@webcity
You can add it at the end of file
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

webcity

  • ****
  • 243 posts
Re: Location filter
« Reply #10 on: March 03, 2018, 12:12:40 PM »
Code: [Select]
if(function_exists('radius_item_loc')) {
  Search::newInstance()->addJoinTable( DB_TABLE_PREFIX.'t_item_radius.item_id', DB_TABLE_PREFIX.'t_item_radius', DB_TABLE_PREFIX.'t_item.pk_i_id = '.DB_TABLE_PREFIX.'t_item_radius.item_id', 'LEFT OUTER' ) ;

  $cd = ModelRadius::newInstance()->getCordByCity(Params::getParam('city'));

  if(@$cd['latitude'] <> '' && @$cd['longitude'] <> '') {
    $sql = sprintf('SQRT(POWER(%st_item_radius.longitude - %d, 2) + POWER(%st_item_radius.latitude - %d, 2))', DB_TABLE_PREFIX, @$cd['longitude'], DB_TABLE_PREFIX, @$cd['latitude']);
 
    Search::newInstance()->order($sql . ' ASC, ' . DB_TABLE_PREFIX.'t_item.dt_pub_date DESC', '');
  }
}

Hi,

When I add it to the end of the functions.php It doesn't seem to make any difference.

I would like to include listings within 20 miles of the town in the results.

Can you suggest what to change in the coding?

Many thanks,
Spencer



*

Ghiz

  • ***
  • 31 posts
Re: Location filter
« Reply #11 on: March 11, 2018, 01:24:06 PM »
I notice that the code you did sent me to add in function.php is already set in stela function.php !!
No use to add these lines !!
sincerly why?? am i wrong??

*

MB Themes

Re: Location filter
« Reply #12 on: March 11, 2018, 08:09:02 PM »
@Ghiz
You mean I sent you?
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ghiz

  • ***
  • 31 posts
Re: Location filter
« Reply #13 on: March 12, 2018, 01:56:27 AM »
Sorry my mistakes WEB CITY did this.
I made a mistake sorry.
Ghiz.

*

webcity

  • ****
  • 243 posts
Re: Location filter
« Reply #14 on: March 12, 2018, 04:32:12 AM »
Code: [Select]
if(function_exists('radius_item_loc')) {
  Search::newInstance()->addJoinTable( DB_TABLE_PREFIX.'t_item_radius.item_id', DB_TABLE_PREFIX.'t_item_radius', DB_TABLE_PREFIX.'t_item.pk_i_id = '.DB_TABLE_PREFIX.'t_item_radius.item_id', 'LEFT OUTER' ) ;

  $cd = ModelRadius::newInstance()->getCordByCity(Params::getParam('city'));

  if(@$cd['latitude'] <> '' && @$cd['longitude'] <> '') {
    $sql = sprintf('SQRT(POWER(%st_item_radius.longitude - %d, 2) + POWER(%st_item_radius.latitude - %d, 2))', DB_TABLE_PREFIX, @$cd['longitude'], DB_TABLE_PREFIX, @$cd['latitude']);
 
    Search::newInstance()->order($sql . ' ASC, ' . DB_TABLE_PREFIX.'t_item.dt_pub_date DESC', '');
  }
}

I've got a personal message asking if I got this code working.

No, it didn't make any difference to the search results when I add it to to the functions.php

It would be great to get this working and even better to add it as a configuration option for a future version of the Radius Search Plugin :-)