Elvinas Posted August 26, 2021 Share Posted August 26, 2021 (edited) So, here's is my custom module that I created. Please see attached. So I have a problem where ModuleFrontController is not accessible it gives me 404 when I try to access it, using this url, that I generated with this code: $this->context->link->getModuleLink($this->name, 'ajax'); It returns this url: http://localhost/test/module/recommended_products_custom/ajax When I visit it, it returns 404, I changed my module's folder name and class and module name, you can see the current structure in the image. And it is strange. It no longer works, could anyone please tell me if I made a mistake renaming, as I don't see it myself and I really feel like I'm following the right naming conventions. Any help is really appreciated. Edited August 26, 2021 by Elvinas (see edit history) Link to comment Share on other sites More sharing options...
endriu107 Posted August 26, 2021 Share Posted August 26, 2021 You need to register controllers by $this->controllers = array('ajax'); Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 (edited) Thanks for your response - endriu107, should I add $this->controllers = array('ajax'); in my recommended_products_custom.php file? Or an Ajax.php? Edited August 26, 2021 by Elvinas (see edit history) Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 (edited) 31 minutes ago, endriu107 said: You need to register controllers by $this->controllers = array('ajax'); Unfortunately it did nothing. Seems really weird, impossible to identify what is wrong. It seems that folder names, module name, and class names are all correctly named. Edited August 26, 2021 by Elvinas (see edit history) Link to comment Share on other sites More sharing options...
endriu107 Posted August 26, 2021 Share Posted August 26, 2021 It should be in recommended_products_custom.php in __construct Link to comment Share on other sites More sharing options...
endriu107 Posted August 26, 2021 Share Posted August 26, 2021 Check in documentation https://devdocs.prestashop.com/1.7/modules/concepts/controllers/front-controllers/ Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 15 minutes ago, endriu107 said: Check in documentation https://devdocs.prestashop.com/1.7/modules/concepts/controllers/front-controllers/ Already did that, seems strange issue that I can't fix. Anyway thanks for trying to help me out Link to comment Share on other sites More sharing options...
endriu107 Posted August 26, 2021 Share Posted August 26, 2021 In initContent did you set template path? Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 11 minutes ago, endriu107 said: In initContent did you set template path? Yes, I did. Please see attached. I think the problem is probably somewhere else, but regardless it is really weird. Because personally I'm not sure if the template path could be related somehow, as I tried to echo out some text at the very beginning of initContent() function and still I got 404 error, so it happens even before the template is fetched. Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 Just now, Elvinas said: Yes, I did. Please see attached. I think the problem is probably somewhere else, but regardless it is really weird. Because personally I'm not sure if the template path could be related somehow, as I tried to echo out some text at the very beginning of initContent() function and still I got 404 error, so it happens even before the template is fetched. Please call parent::initContent(); in your initContent function Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 Call like this Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 (edited) I uploaded an image, please see attached. So my module's folder name is: 'recommended_products_custom The main module's file name is: recommended_products_custom.php (the same as folder name + .php) The main module's file class name is: Recommended_Products_Custom The front controller file name is: ajax.php and class name: Recommended_Products_CustomAjaxAjaxModuleFrontController when it should have been Recommended_Products_CustomAjaxModuleFrontController (only one Ajax word). And to my surprise it still does not work. Even after addint parent::initContent(); and such. Looks like I found the naming problem and it still didn't solve this, just wow. Thanks guys for trying to help me Edited August 26, 2021 by Elvinas (see edit history) Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 So your issue is resolved. Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 Module files. recommended_products_custom.zip Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 1 minute ago, Shabab said: So your issue is resolved. Nope it's not. Sorry maybe I wasn't clear, I fixed the typo that I made but it still didn't solve it. Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 Ok let me check your module Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 26, 2021 Share Posted August 26, 2021 18 minutes ago, Elvinas said: Nope it's not. Sorry maybe I wasn't clear, I fixed the typo that I made but it still didn't solve it. Just try to comment this line /1.7.7.0/modules/recommended_products_custom/controllers/front/ajax.php public function __construct() { $this->templateFile = 'module:recommended_products_custom/views/templates/hook/recommended_products_custom.tpl'; } you will see the message in browser Direct access not allowed. in my case the frontend url is http://localhost:8888/ps/1.7.7.0/en/module/recommended_products_custom/ajax Hope it will help you. Thank you Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 Issue fixed. The main issue is in your tpl file . you write js in tpl file and it requires j query that's why it is not working . I separated JS code in JS file . Install this module and check it. Thanks recommended_products_custom.zip Link to comment Share on other sites More sharing options...
Elvinas Posted August 26, 2021 Author Share Posted August 26, 2021 Thanks guys for your help. Unfortunately I can't try out your solutions for now. I'm unable to delete the module from prestashop. It says: Cannot uninstall module recommended_products_custom. The module is not installed. I tried deleting the module directory manually, it did disappear, but when I copy and paste it back it shows that it is somehow installed, and I can't uninstall and make a fresh install. So looking for the info how to solve it, then I can try your provided examples. I really appreciate time you took to answer me. Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 26, 2021 Share Posted August 26, 2021 @Elvinas You not need to uninstall the file as brother Shahab add nothing much which need to reinstall the module just replace the module you will see it work. Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 4 minutes ago, SmartDataSoft said: @Elvinas You not need to uninstall the file as brother Shahab add nothing much which need to reinstall the module just replace the module you will see it work. No i Add new hook in module so he need to install the module again Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 26, 2021 Share Posted August 26, 2021 2 minutes ago, Shabab said: No i Add new hook in module so he need to install the module again oh, Sorry, I have missed that. Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 26, 2021 Share Posted August 26, 2021 Please change it public function hookHeader() { $this->context->controller->addJS($this->_path . '/views/js/front.js'); } to public function hookHeader() { $this->context->controller->addJS($this->_path . 'views/js/front.js'); } other wise it will add a extra / <script type="text/javascript" src="http://localhost:8888/ps/1.7.7.0/modules/recommended_products_custom//views/js/front.js" ></script> Thank you Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 It's same code . It's not adding extra. Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 26, 2021 Share Posted August 26, 2021 6 minutes ago, Shabab said: It's same code . It's not adding extra. Please check brother before view it add two // which will be / , i checked my self from view source Link to comment Share on other sites More sharing options...
Shabab Posted August 26, 2021 Share Posted August 26, 2021 3 minutes ago, SmartDataSoft said: Please check brother before view it add two // which will be / , i checked my self from view source Yes but both have different paths Link to comment Share on other sites More sharing options...
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