Simetria Posted February 25, 2019 Share Posted February 25, 2019 (edited) Hi All, I have a piece of custom PHP code that I need to place somewhere in the file structure that would be accessible on all pages (cart, cats, cms, etc...). I have done digging around and see all fingers pointed at the controllers directory. I'm not really sure where/how to make the addition. I've tried to create a module, but getting stuck - abandoning this idea due to time crunch. Any help would be extremely appreciated. Also I should note that I would need to access the output of the custom PHP code via AJAX from the frontend. I have all this hooked up and working on just a simple setup (XAMPP) php.php & js.js just need to know how to integrate it within Prestashop's structure. Ideally this code would run early on in the lifecycles, and if I don't have to override any core file/s, even better. Thanks so much for any help. EDIT: Using PS version 1.7.5 Edited February 25, 2019 by Simetria (see edit history) Link to comment Share on other sites More sharing options...
tdsoft Posted February 26, 2019 Share Posted February 26, 2019 You should learn to become a Developer Prestashop at here: https://devdocs.prestashop.com/1.7/basics/introduction/ Link to comment Share on other sites More sharing options...
Simetria Posted February 26, 2019 Author Share Posted February 26, 2019 7 minutes ago, tdsoft said: You should learn to become a Developer Prestashop at here: https://devdocs.prestashop.com/1.7/basics/introduction/ I appreciate the encouraging words, but a little insight on my initial question/request would be much more appreciated. Link to comment Share on other sites More sharing options...
tdsoft Posted February 26, 2019 Share Posted February 26, 2019 Please summary your question for your problem because nobody can take much time to teach you how to develope a module 1 Link to comment Share on other sites More sharing options...
Simetria Posted February 26, 2019 Author Share Posted February 26, 2019 If you read my initial post, I did not ask for anyone to teach me how to develop a module or anything. I simply asked where (semantically) can I place custom PHP code that can be accessible on all pages (cart, cats, cms, etc...). Then I said "I've tried to create a module, but getting stuck - abandoning this idea due to time crunch". Thanks. Link to comment Share on other sites More sharing options...
JBW Posted February 26, 2019 Share Posted February 26, 2019 Hi Simetria, The best way is to develop a module. If you use the generator (https://validator.prestashop.com/generator) it should be rather easy - to have your code executed on every page you can add it to diplayHeader hook for example. If you want to use any output on the frontend then assign it to smarty and insert these in the theme template file. Best regards Link to comment Share on other sites More sharing options...
Simetria Posted February 26, 2019 Author Share Posted February 26, 2019 Thank you JBW, I have tried to create a module via the generator, but when I do a simple test I get a 500 error. For example, in the hookDisplayHeader function, if I write this: public function hookDisplayHeader(){ /* Place your code here. */ Media::addJsDef('simVar' => 'Test.'); } or instead this: public function hookDisplayHeader(){ /* Place your code here. */ $this->context->smarty->assign('simVar' => 'Hello'); } both examples above breaks the site and I get a 500 error. Am I missing something? Link to comment Share on other sites More sharing options...
JBW Posted February 26, 2019 Share Posted February 26, 2019 Activate Presta Debug Mode to see the details of the error. Why are you using => in your smarty example, value should be second parameter. Link to comment Share on other sites More sharing options...
Simetria Posted February 26, 2019 Author Share Posted February 26, 2019 3 minutes ago, JBW said: Why are you using => HOLLY S#!t I cannot believe I missed that... Thanks, JBW so far so goo, I am able to pass the smarty var to the tpl file with no issues. Link to comment Share on other sites More sharing options...
Ezequielb Posted May 29, 2020 Share Posted May 29, 2020 On 2/25/2019 at 11:17 PM, tdsoft said: Please summary your question for your problem because nobody can take much time to teach you how to develope a module @tdsoft I don't see anybody putting a gun in your head and asking to teach someone to be a developer. If your are no interested in the topic, just close the window. Even more if you are from the buy-addons team, which don't comment their code and when you ask them for a modification the say its too hard to do.. How could you to teach someone if you can't do it by yourself??? 1 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