Advertisement:

Author Topic: [RESOLVED] Exclude category from results search ajax autocomplete  (Read 699 times)

leuname07

  • Newbie
  • *
  • Posts: 39
Hello,

I need to exclude my adult category in ajax autocomplete results. Anyone can help me ? This the code and my theme is Veronika.

Code: [Select]
<div class="header-search-mobile is767">
  <form action="<?php echo osc_base_url(true); ?>" method="get" class="search nocsrf" >
    <input type="hidden" name="page" value="search" />

    <div class="input-box">
      <button type="submit"><i class="fa fa-search"></i></button>
      <input type="text" name="sPattern" id="query" value="<?php echo osc_esc_html(osc_search_pattern()); ?>" placeholder="<?php _e('Search...''veronika'); ?>" autocomplete="off" />
    </div>

    <i class="fa fa-ellipsis-v open-h-search"></i>
  </form>
</div>


<?php if(osc_get_preference('search_box_home''veronika_theme') == '1') { ?>
  <div id="header-search">
    <div class="inside">
      <div class="wrap round3">
                <form action="<?php echo osc_base_url(true); ?>" method="get" class="search nocsrf" >
          <input type="hidden" name="page" value="search" />
          <input type="hidden" name="cookieAction" id="cookieAction" value="" />
          <input type="hidden" name="sCountry" id="sCountry" value="<?php echo Params::getParam('sCountry'); ?>"/>
          <input type="hidden" name="sRegion" id="sRegion" value="<?php echo Params::getParam('sRegion'); ?>"/>
          <input type="hidden" name="sCity" id="sCity" value="<?php echo Params::getParam('sCity'); ?>"/>

          <div class="top">
            <div class="large">
              <div class="b1">
                <div class="label"><h1><?php _e('Petites annonces gratuites - Que cherchez-vous ?''veronika'); ?></h1></div>
                <div class="box">
                  <?php if (osc_get_preference('item_ajax''veronika_theme') == 1) { ?>
                    <div id="item-picker">
                      <input type="text" name="sPattern" class="pattern" placeholder="<?php _e('Samsung S7 Edge...''veronika'); ?>" value="<?php echo Params::getParam('sPattern'); ?>" autocomplete="off"/>

                      <div class="shower-wrap">
                        <div class="shower" id="shower">
                          <div class="option service min-char"><?php _e('Type keyword''veronika'); ?></div>
                        </div>
                      </div>

                      <div class="loader"></div>
                    </div>
                  <?php } else { ?>
                    <input type="text" name="sPattern" placeholder="<?php _e('Samsung S7 Edge...''veronika'); ?>" value="<?php echo Params::getParam('sPattern'); ?>" autocomplete="off"/>
                  <?php ?>
                </div>
              </div>

              <div class="b3">
                <div class="label">&nbsp;</div>
                <div class="box"><button type="submit" class="round3 tr1"><?php _e('Search''veronika'); ?></button></div>
              </div>
            </div>
            </div>
          </div>

        </div>
      </form>
    </div>
  </div>
<?php ?>
« Last Edit: July 19, 2019, 06:01:11 pm by leuname07 »

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #1 on: June 14, 2019, 02:51:07 pm »
Help... please !

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #2 on: June 14, 2019, 10:44:02 pm »
Hello!

This is a premium theme, which means I don't have access to it. You did provide some code but it's not enough. I believe we need autocomplete JS and AJAX function for autocomplete to (try to) do something...

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #3 on: June 15, 2019, 01:51:57 am »
This is the code in footer :

Code: [Select]
    <?php if(osc_get_preference('item_ajax''veronika_theme') == 1) { ?>
      // JAVASCRIPT AJAX LOADER FOR ITEMS AUTOCOMPLETE
      var patternClicked = false;

      // On first click initiate loading
      $('body').on('click', '#item-picker .pattern', function() {
        if( !patternClicked ) {
          $(this).keyup();
        }

        patternClicked = true;
      });


      // Create delay
      var delay2 = (function(){
        var timer2 = 0;
        return function(callback, ms){
          clearTimeout (timer2);
          timer2 = setTimeout(callback, ms);
        };
      })();


      //$(document).ajaxStart(function() {
        //$("#item-picker, .item-picker").addClass('searching');
      //});

      $(document).ajaxSend(function(evt, request, settings) {
        var url = settings.url;

        if (url.indexOf("ajaxItem") >= 0) {
          $("#item-picker, .item-picker").addClass('searching');
        }
      });

      $(document).ajaxStop(function() {
        $("#item-picker, .item-picker").removeClass('searching');
      });


      $('body').on('keyup', '#item-picker .pattern', function(e) {
        delay(function(){
          var min_length = 3;
          var elem = $(e.target);
          var pattern = elem.val();

          var block = elem.closest("#item-picker");
          var shower = elem.closest("#item-picker").find(".shower");

          shower.html('');

          if(pattern != '' && pattern.length >= min_length) {
            // Combined ajax for country, region & city
            $.ajax({
              type: "POST",
              url: baseAjaxUrl + "&ajaxItem=1&pattern=" + pattern,
              dataType: 'json',
              success: function(data) {
                var length = data.length;
                var result = '';

                if(shower.find('.service.min-char').length <= 0) {
                  for(key in data) {
                 
                    // When item already is not in shower
                    if(shower.find('div[data-item-id="' + data[key].pk_i_id + '"]').length <= 0) {
                      result += '<a class="option" data-item-id="' + data[key].pk_i_id + '" href="' + data[key].item_url + '" title="<?php echo osc_esc_js(__('Click to open listing''veronika')); ?>">'
                      result += '<div class="left"><img src="' + data[key].image_url + '"/></div>';
                      result += '<div class="right">';
                      result += '<div class="top">' + data[key].s_title + '</div>';
                      result += '<div class="bottom">' + data[key].i_price + '</div>';
                      result += '</div>';
                      result += '</a>';
                    }
                  }


                  // No city, region or country found
                  if( length <= 0) {
                    shower.find('.option').remove();
                    result = '<div class="option service empty-pick"><?php echo osc_esc_js(__('No listing match to your criteria''veronika')); ?></div>';
                  }
                }

                shower.html(result);
              }
            });

          } else {
            // Term is not length enough
            shower.html('<div class="option service min-char"><?php echo osc_esc_js(__('Enter at least''veronika')); ?> ' + (min_length - pattern.length) + ' <?php echo osc_esc_js(__('more letter(s)''veronika')); ?></div>');
          }
        }, 500 );
      });
    <?php ?>

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #4 on: June 19, 2019, 01:57:10 am »
Any help please ?

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #5 on: June 25, 2019, 11:11:42 am »
Managed to get my hands on the theme code in meanwhile...

Open oc-content/themes/veronika/ajax.php.

Go to line 70.

Add this to the end of it AND i.fk_i_category_id NOT IN (1,2,3,4).

Replace 1,2,3,4 with your category ID's.

The final line should look like this: WHERE d.fk_c_locale_code = '" . osc_current_user_locale() . "' AND (s_title LIKE '%" . $pattern . "%' OR s_description LIKE '%" . $pattern . "%') AND i.fk_i_category_id NOT IN (1,2,3,4)


I didn't test but it should work.

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #6 on: June 28, 2019, 11:02:16 pm »
Hello,

Don't work.

I don't have error.

i have modified this :

Code: [Select]
   WHERE d.fk_c_locale_code = '" . osc_current_user_locale() . "' AND (s_title LIKE '%" . $pattern . "%' OR s_description LIKE '%" . $pattern . "%') AND i.fk_i_category_id NOT IN (327, 326, 325, 324, 323, 322, 321, 320, 1335, 1334, 1333, 1332, 1331, 1330, 1329, 1328, 1327, 319, 318, 317, 316, 1326, 1325, 315, 314, 1324, 1323, 313, 312, 311, 1322, 1321, 1320, 1319, 310, 209, 308, 1318, 1317, 307, 107)

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #7 on: June 28, 2019, 11:18:30 pm »
Try replacing "i.fk_i_category_id" with just "fk_i_category_id". Not sure.

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #8 on: June 28, 2019, 11:36:38 pm »
The same thing, don't work and no error.

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #9 on: June 29, 2019, 12:08:27 am »
https://doc.osclass.org/Debug_SQL_queries

Add this to config.php:

Code: [Select]
define('OSC_DEBUG_DB', true) ;
define('OSC_DEBUG_DB_LOG', true) ;

Open oc-content. Create file 'queries.log'.

Refresh site. Post queries.log here.

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #10 on: June 29, 2019, 01:23:47 am »
Ok, i cancel the last change for the log.

Do you need with the change i.fk_..... ??

You have the log in attachment !!!

Thank you

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #11 on: June 30, 2019, 01:24:41 am »
Don't see what's the issue... :/ I will do some tests on Veronika when I get time.

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #12 on: June 30, 2019, 02:58:10 am »
Ok. Thank you for your time.

WEBmods

  • Hero Member
  • *****
  • Posts: 936
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #13 on: July 06, 2019, 02:13:12 am »
Now I need your help...  ;D

http://148.251.207.178/osclass/plugins/demo/

I'm wanted to test autocomplete. I didn't change anything, just installed the theme, but on my site, it doesn't work at all. Just spinning circle. Is there something I need to enable or?

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #14 on: July 06, 2019, 04:41:56 pm »
You have to enable the autocomplete in theme setting.