j.kaspar Posted April 12, 2019 Share Posted April 12, 2019 Hi, I have problem with a HelperList filter reset. On a form with a list created via HelperList $helper = new HelperList(); $helper->identifier = 'id_product'; $helper->table_id = 'js-product-list'; $helper->title = 'ProductList'; $helper->table = $table_name; $helper->simple_header = false; $helper->shopLinkType = ''; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->imageType = 'jpg'; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->no_link = false; I use filters which work fine, but the button supposed to reset the filter just behaves the same way as the actual submit buton - submits the filters. On click, the page reloads and the submitReset*** parameter is being set correctly. From what I found out, the reset should be functional by itself, with no need to program anything else. Other "prestashop native" lists work fine and the only difference I spotted is the fact, that after clicking on the "working" reset button, the "network" console in the browser shows, that the page is being loaded twice - once with the submitReset*** parameter set and then redirected with HTTP code 302 and loaded second time with filtering parameters unset. The mine one loads only once. No redirection happens. Can someone please help me to find the cause? Link to comment Share on other sites More sharing options...
Janett Posted April 12, 2019 Share Posted April 12, 2019 You are in an AdminController or in a Module ? Where did you assign list column ? Link to comment Share on other sites More sharing options...
j.kaspar Posted April 12, 2019 Author Share Posted April 12, 2019 @Janett, it is on a module configuration page, controller=AdminModules Link to comment Share on other sites More sharing options...
Janett Posted April 12, 2019 Share Posted April 12, 2019 Ok, the helperList inside a Module::getContent() is not a good idea because submitReset are handled in AdminController::initProcess(), when you are in a Module::getContent() your assignment of list is done after AdminController::init() so it's not working. You should create an ModuleAdminController to access all useful method available for helpers. I don't use Module::getContent() anymore in my modules, in fact I just use it to make a redirection to my ModuleAdminController. If you use an helperList inside a Module::getContent() you cannot use advanced features of this helper which is designed to be used in an AdminController, usage in Module::getContent() is tricky, I think it's a bad practice. Did you know how to create an ModuleAdminController ? 1 Link to comment Share on other sites More sharing options...
j.kaspar Posted April 12, 2019 Author Share Posted April 12, 2019 @Janett, I see. Thank you. I have a basic idea how to create a new contoller, like where to place the file, that it is going to be a new class extending ModuleAdminController etc. But If you could recommend me any guide or give me some tips, I will be glad. Thanks! Link to comment Share on other sites More sharing options...
Janett Posted April 12, 2019 Share Posted April 12, 2019 So you need an ObjectModel too. I'm I only find good example for 1.7+, I am not fine with example I find for 1.5/1.6 example. I will try to do it, can you please tell me if you need to use multilang fields or multishop in your module ? Link to comment Share on other sites More sharing options...
j.kaspar Posted April 12, 2019 Author Share Posted April 12, 2019 I don't necessarily need either of those (multishop, multilang), but would be nice to know what difference does it make if I would. Many thanks for your help Link to comment Share on other sites More sharing options...
j.kaspar Posted April 12, 2019 Author Share Posted April 12, 2019 (edited) I found an interesting article regarding the ObjectModel here https://belvg.com/blog/objectmodel-activerecord-in-prestashop.html and also how to create a controller https://belvg.com/blog/how-to-use-the-class-admincontroller-in-prestashop.html Edited April 12, 2019 by j.kaspar (see edit history) Link to comment Share on other sites More sharing options...
j.kaspar Posted April 13, 2019 Author Share Posted April 13, 2019 @Janett, I must be doing something wrong. I created a new controller that extends ModuleAdminController, Module::GetContent() is redirecting to it, the content is being handled by the new controller and displayed on a new admin tab, but unfortunatelly, the behavior is 100% same. Everything works, but the filter reset button. Link to comment Share on other sites More sharing options...
Janett Posted April 14, 2019 Share Posted April 14, 2019 You should declare $this->fields_list inside constructor. You can see for example https://github.com/PrestaShop/PrestaShop/blob/develop/controllers/admin/AdminGendersController.php if you don’t do it inside the constructor, AdminController::init() doesn’t have data to make AdminController::initProcess() and initialization of SubmitReset*** Same for $this->fields_options for HelperOption et $this->fields_form for HelperForm. They must be declared inside constructor. Its a common mistake to do it inside renderList() or renderForm() or renderOptions() You also have to declare in constructor $this->table and $this->className (name of your ObjectModel) Link to comment Share on other sites More sharing options...
j.kaspar Posted April 14, 2019 Author Share Posted April 14, 2019 @Janett, thank you for your advices. It turned out, that my assumption, that the reset action doesn't need any further programing and that it works "out of box" was wrong. The solution is simple: if (Tools::isSubmit('submitReset'.$this->table_name)) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminTag')); } ... in the InitContent() function of my controller Link to comment Share on other sites More sharing options...
Janett Posted April 14, 2019 Share Posted April 14, 2019 It works by default, I use it in many modules Why do a redirection in this case ? That's weird don't do that. You can send me your code in private if you don't want to show it here, I will check it. Link to comment Share on other sites More sharing options...
Recommended Posts