Advertisement:

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

galaxypower

  • Newbie
  • *
  • Posts: 8
Re: Exclude category from results search ajax autocomplete
« Reply #30 on: July 15, 2019, 09:56:57 am »
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)


this should work, did you try it ?

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #31 on: July 15, 2019, 11:20:17 pm »
Hello,

No, it's doesn't work. No "results" in adult category !

Thank you for your help...

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #32 on: July 15, 2019, 11:36:31 pm »
I tested 'osc_search_category_id()[0]' function on search page of Veronika theme and it does return category ID. There is a problem somewhere else that I still didn't found.

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #33 on: July 17, 2019, 06:53:18 pm »
Any news, solutions ? Thanks for your help.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Exclude category from results search ajax autocomplete
« Reply #34 on: July 19, 2019, 02:25:44 pm »
New SQL code:

Code: [Select]
      $category = (int) Params::getParam('category');
      $removed_categories = array(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);
      if(in_array($category, $removed_categories)) { // If current search category is on the list of removed ones, show all categories.
          $sql = "
              SELECT i.pk_i_id, d.s_title, i.i_price, i.fk_c_currency_code, CONCAT(r.s_path, r.pk_i_id,'_thumbnail.',r.s_extension) as image_url
              FROM {$db_prefix}t_item i
              INNER JOIN {$db_prefix}t_item_description d
              ON d.fk_i_item_id = i.pk_i_id
              LEFT OUTER JOIN {$db_prefix}t_item_resource r
              ON r.fk_i_item_id = i.pk_i_id AND r.pk_i_id = (
                SELECT rs.pk_i_id
                FROM {$db_prefix}t_item_resource rs
                WHERE i.pk_i_id = rs.fk_i_item_id
                LIMIT 1
              )

              WHERE d.fk_c_locale_code = '" . osc_current_user_locale() . "' AND (s_title LIKE '%" . $pattern . "%' OR s_description LIKE '%" . $pattern . "%') AND b_active = 1 AND b_enabled = 1 AND b_spam = 0
              ORDER BY dt_pub_date DESC
              LIMIT " . $max . ";
            ";
      } else { // Otherwise remove categories on the list.
          $sql = "
              SELECT i.pk_i_id, i.fk_i_category_id, d.s_title, i.i_price, i.fk_c_currency_code, CONCAT(r.s_path, r.pk_i_id,'_thumbnail.',r.s_extension) as image_url
              FROM {$db_prefix}t_item i
              INNER JOIN {$db_prefix}t_item_description d
              ON d.fk_i_item_id = i.pk_i_id
              LEFT OUTER JOIN {$db_prefix}t_item_resource r
              ON r.fk_i_item_id = i.pk_i_id AND r.pk_i_id = (
                SELECT rs.pk_i_id
                FROM {$db_prefix}t_item_resource rs
                WHERE i.pk_i_id = rs.fk_i_item_id
                LIMIT 1
              )

              WHERE d.fk_c_locale_code = '" . osc_current_user_locale() . "' AND (s_title LIKE '%" . $pattern . "%' OR s_description LIKE '%" . $pattern . "%') AND b_active = 1 AND b_enabled = 1 AND b_spam = 0 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)
              ORDER BY dt_pub_date DESC
              LIMIT " . $max . ";
            ";
      }

Modifying footer.php to send category ID:

Code: [Select]
    <?php if(osc_get_preference('item_ajax''veronika_theme') == 1) { ?>
      // JAVASCRIPT AJAX LOADER FOR ITEMS AUTOCOMPLETE
      var category = <?php echo (array_key_exists(0osc_search_category_id())) ? osc_search_category_id()[0].';' '"";'?>
      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 + "&category=" + category,
              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 ?>

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Exclude category from results search ajax autocomplete
« Reply #35 on: July 19, 2019, 05:59:39 pm »
YESSSS !!!

Thank you ! This working !

You're the best !

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: [RESOLVED] Exclude category from results search ajax autocomplete
« Reply #36 on: July 19, 2019, 10:37:19 pm »
You're welcome! :)

Regards.