Jump to content
thirty bees forum

Keywords autocomplete in the products page


ssimard

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

Link to comment
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
Link to comment
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

Link to comment
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

Link to comment
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?

Link to comment
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} ```

Link to comment
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

Link to comment
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 ?

Link to comment
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.

Link to comment
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 :-/

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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...