ssimard Posted January 29, 2018 Posted January 29, 2018 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) :
ssimard Posted January 30, 2018 Author Posted January 30, 2018 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); } } ``` 1
Lathaneo Posted January 31, 2018 Posted January 31, 2018 Hi, Tagify doesn't work with jquery autocomplete. Tagify use only the widget factory of JqueryUI. Regards.
ssimard Posted January 31, 2018 Author Posted January 31, 2018 @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.
Lathaneo Posted January 31, 2018 Posted January 31, 2018 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.
ssimard Posted January 31, 2018 Author Posted January 31, 2018 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
zimmer-media Posted January 31, 2018 Posted January 31, 2018 @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?
ssimard Posted February 1, 2018 Author Posted February 1, 2018 @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} ```
zimmer-media Posted February 1, 2018 Posted February 1, 2018 @ssimard thanks for your answer if i try the last code it works, but if i use the code ``` {literal} {/literal} ``` i want to change my products i see this i try many changes but no luck
ssimard Posted February 2, 2018 Author Posted February 2, 2018 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 ?
zimmer-media Posted February 2, 2018 Posted February 2, 2018 @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.
ssimard Posted February 2, 2018 Author Posted February 2, 2018 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 :-/
ssimard Posted February 2, 2018 Author Posted February 2, 2018 If you had an overriden product.php already then you should just add the function into it..
zimmer-media Posted February 2, 2018 Posted February 2, 2018 @ssimard Now it works - great thanks. Unfortunately, I did not notice that in the code the class was missing.
ssimard Posted February 2, 2018 Author Posted February 2, 2018 I updated my answer with proper code too.
zimmer-media Posted February 2, 2018 Posted February 2, 2018 @wakabayashi and other moderators i think this topic can move to the category "tips & tricks"
zimmer-media Posted February 2, 2018 Posted February 2, 2018 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.
ssimard Posted February 2, 2018 Author Posted February 2, 2018 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.
movieseals Posted February 4, 2018 Posted February 4, 2018 Forgive my ignorance but informations.tpl is located where?
Lathaneo Posted February 4, 2018 Posted February 4, 2018 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.
Beeta Posted February 5, 2018 Posted February 5, 2018 how about moving this to Tips and Tricks? ...or add it to the core?
ssimard Posted February 5, 2018 Author Posted February 5, 2018 I don't think I can move it myself, or can I ?
zimmer-media Posted February 16, 2018 Posted February 16, 2018 please please please admins or moderators -> move this topic to the category “tips & tricks” we are think category "technical help" is between false
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now