Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

ssimard

Keywords autocomplete in the products page

Recommended Posts

I am trying to get autocomplete to work in the keywords field but can't figure how to do it.

The tags are created using tagify (https://github.com/alicial/jQuery.Tagify) and the demo is working fine..

It is supposed to work with JQueryUI autocomplete so I've added 'ui.autocomplete' to the list of js files in the controller.

Is there any other dependencies ? Anyone got this to work ?

Here's the Javascript I am using in informations.tpl:

``` {literal}

{/literal} ``` Sorry, I hit the post button too early.. here's a screenshot of the field (keywords is 'Mots-clés' in french) : 0_1517255842930_Capture d’écran 2018-01-29 à 14.50.45.png

Share this post


Link to post
Share on other sites

There was a conflict between JQueryUI and standard JQuery it seems.. here's what I did in the end using standard JQuery autocomplete:

Informations.tpl ``` {literal}

{/literal} ```

Tag.php class Tag extends TagCore { public static function getTags($id_lang, $nb = 10) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT t.`name` FROM `'._DB_PREFIX_.'tag` t WHERE t.`id_lang` = '.(int)$id_lang.' ORDER BY t.`name` ASC'); //I commented this out since I need them all and not only the first 10. Could be useful to someone, I don't know. //LIMIT 0, '.(int)$nb); } }

Product.php, added this function: ``` class Product extends ProductCore{ public function getAllTags($idlang = 0, $qty = 10){ if(!$idlang){ $context = Context::getContext(); $id_lang = $context->language->id; }

    return Tag::getTags($id_lang, $qty);
}

} ```

  • Thanks 1

Share this post


Link to post
Share on other sites

Hi,

Tagify doesn't work with jquery autocomplete. Tagify use only the widget factory of JqueryUI.

Regards.

Share this post


Link to post
Share on other sites

@lathaneo said in Keywords autocomplete in the products page:

Hi,

Tagify doesn't work with jquery autocomplete. Tagify use only the widget factory of JqueryUI.

Regards.

I only wanted to make it easier to choose keywords while typing. I have several keywords that are the same for several books (kinda like bisac codes if you're familiar).

It is working now with JQuery autocomplete (see the code I posted). The only downside is that you have to click once to select it then ENTER in order to confirm.

0_1517407994201_Capture d’écran 2018-01-31 à 09.12.38.png

Share this post


Link to post
Share on other sites

Yes,

It's a nice feature, for only some lines more. I'm trying the code, but i get a error of line"" illegal recursive call of "".

Regards.

Share this post


Link to post
Share on other sites

I forgot to mention that you have to override product.php, of course, and delete the cache file.. (class_index.php).

-> /override/controllers/admin/templates/products/informations.tpl -> /override/classes/Tag.php -> /override/classes/Product.php

Share this post


Link to post
Share on other sites

@ssimard

This looks very good on your pictures. Could be in the category Tips & Tricks. ;) Something like that I have previously searched with PS. Unfortunately, it does not work with TB for me. Are these all the steps that need to be done or should more data be loaded on the server?

I have tried to replace the lines in informations.tpl with different possibilities. Which lines did you overwrite?

Share this post


Link to post
Share on other sites

@zimmer-media

You should be good if you modify the 3 files I pointed out in my previous post.

You can do a quick test and just pass a manual list of keywords to the autocomplete function in Informations.tpl. -> /override/controllers/admin/templates/products/informations.tpl

Find the code in the original file(between line 438 and 448) and replace it with this:

``` {literal}

{/literal} ```

Share this post


Link to post
Share on other sites

@ssimard thanks for your answer if i try the last code it works, but if i use the code

0_1517519277995_Neues Bild (7-1).bmp

``` {literal}

{/literal} ``` i want to change my products i see this

0_1517518870990_8969b1d4-75ed-4d68-8c23-55d4760d06e7-grafik.png

i try many changes but no luck

Share this post


Link to post
Share on other sites

You have to override the Tag class for this to work. Look in my accepted answer.

Basically, it is just an SQL request that retrieves entries in the tag database. It is called by the getAllTags function that you have to add to product.php class as well.

Make sure that you have datas in that table.

I can't read German, what does the full error means ?

Share this post


Link to post
Share on other sites

@ssimard

I have data in the tag table. I've also created the two overrides Tag.php and Product.php.

In the second picture there are no errors. only the white background and part of the informations.tpl with the product data.

The cache is emptied and the class_index.php deleted. With Debug Mod On I get no error messages.

The same negative result I get on another server with another shop.

Share this post


Link to post
Share on other sites

I'm not sure why it's not working, I haven't posted the full override code for product.php but I assume that you've done it properly ?

``` class Product extends ProductCore{ public function getAllTags($idlang = 0, $qty = 10){ if(!$idlang){ $context = Context::getContext(); $id_lang = $context->language->id; }

    return Tag::getTags($id_lang, $qty);
}

} ```

I'm really sorry, I fail to see why it is not working on your end :-/

Share this post


Link to post
Share on other sites

If you had an overriden product.php already then you should just add the function into it..

Share this post


Link to post
Share on other sites

So the work is much easier. With every tag entry, we had to be careful that it was correct. A wrong letter and the extra work was there.

It's finally been easier for a few years now.

Share this post


Link to post
Share on other sites

I'm glad that you find it useful, it definitely makes life easier for me since I am tagging books on multiple pre-defined keywords.

Share this post


Link to post
Share on other sites

Hi,

admin-dev\themes\default\template\controllers\products\informations.tpl

And as said @ssimard, you can override like that:

-> /override/controllers/admin/templates/products/informations.tpl -> /override/classes/Tag.php -> /override/classes/Product.php

Regards.

Share this post


Link to post
Share on other sites

please please please admins or moderators -> move this topic to the category “tips & tricks” we are think category "technical help" is between false

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...