Osclass forums

Support forums => Themes => Topic started by: leuname07 on June 13, 2019, 12:42:34 am

Title: Exclude category from results search ajax autocomplete
Post by: leuname07 on June 13, 2019, 12:42:34 am
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 ?>
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on June 14, 2019, 02:51:07 pm
Help... please !
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods 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.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 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 ?>
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on June 19, 2019, 01:57:10 am
Any help please ?
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods 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.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 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)
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on June 28, 2019, 11:18:30 pm
Try replacing "i.fk_i_category_id" with just "fk_i_category_id". Not sure.

Regards.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on June 28, 2019, 11:36:38 pm
The same thing, don't work and no error.
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods 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.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 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
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods 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.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on June 30, 2019, 02:58:10 am
Ok. Thank you for your time.
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods 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.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 06, 2019, 04:41:56 pm
You have to enable the autocomplete in theme setting.
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on July 06, 2019, 06:56:30 pm
(https://i.postimg.cc/DZsHn5XG/Izrezak.png)
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 07, 2019, 12:36:34 am
Yes ! But don't work ?

Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 07, 2019, 12:37:40 am
You can try in my website : www.natava.ch !
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 07, 2019, 12:42:26 am
You have check this error in your website test ?


(https://ibb.co/sKMcRRv)
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 07, 2019, 12:43:51 am
(https://i.ibb.co/6HfGwwR/Sans-titre-1.jpg) (https://ibb.co/sKMcRRv)
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on July 08, 2019, 01:32:46 pm
Let me try on another site.

Regards.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 12, 2019, 02:00:55 pm
Any news ?
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on July 12, 2019, 03:51:22 pm
Now try this. Apparently, the AJAX code is now in the contact.php file, while it was in the ajax.php file previously. Whole Veronika AJAX system is weird and it's not using Osclass AJAX calls...

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

Go to line 54.
Make it look like this 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.

Go to line 67.
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.

Regards.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 12, 2019, 11:34:55 pm
Now, i have 0 result when i make a search.

Code: [Select]
    $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
        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)
       
        LIMIT " . $max . ";
       
       
      ";
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on July 13, 2019, 12:35:29 am
Wrong line I guess.

Code: [Select]
    $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 . ";
       
       
      ";

Regards.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 13, 2019, 12:45:30 am
YESSS ! Thank you ! It's OK when the user is not in the adult categories.

You think it's hard to enable the search in this category when the user is in category adult because now when the user is in the category adult and make a search, he does'nt have results for this category.

Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on July 13, 2019, 01:26:25 am
We finally got it working! ;)

Try this:

Code: [Select]
$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(@osc_search_category_id()[0], $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 . ";
      ";
}

Regards.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 13, 2019, 01:33:08 am
It's OK for the search in all categories but in adult "no results" ! You can see here :

https://www.natava.ch/erotique
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods on July 13, 2019, 07:25:33 pm
Probably an issue with 'osc_search_category_id()[0]'. Let me test something.

Regards.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 14, 2019, 11:20:10 pm
Ok, thank you for your help !
Title: Re: Exclude category from results search ajax autocomplete
Post by: galaxypower 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 ?
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 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...
Title: Re: Exclude category from results search ajax autocomplete
Post by: WEBmods 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.
Title: Re: Exclude category from results search ajax autocomplete
Post by: leuname07 on July 17, 2019, 06:53:18 pm
Any news, solutions ? Thanks for your help.