pedrogon Posted September 13, 2013 Share Posted September 13, 2013 (edited) Hi, I want to use insert some php code (this: http://www.finalwebsites.com/forums/topic/how-to-use-maxmind-geoip-for-websites#post-1591) in order to show the result in the right column of my site. I've read quite a bit about this and I got the impression that the cleanest solution is to create a custom module (please, tell me if I'm wrong and there is a better solution). I've created my custom module following the instructions of http://www.technoreply.com/how-to-create-a-prestashop-1-5-module/ and a little bit of http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module. It works OK for showing some text (either putting the text directly in the tpl file or putting something like 'mymodule_message' => $this->l('example text') in mymodule.php). But I don't want show a "fixed" text message, I want to insert php code and show the result of that code. I don't have any idea of where shoud I put the php code to make it work. Now the "interesting" part of mymodule.php says: public function hookDisplayLeftColumn() { $this->context->smarty->assign(array( 'placement' => 'left', 'my_module_message' => $this->l('example text') // Do not forget to enclose your strings in the l() translation method )); return $this->display(__FILE__, 'left.tpl'); } Should I put the php code in this part, create a new php file and call it from here or what? Thanks for your help and sorry for asking noobie questions, but that's what I am right now (I don't know much about prestashop or php, but willing to learn)... Edited September 17, 2013 by pedrogon (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted September 13, 2013 Share Posted September 13, 2013 if you want a variable text in my_module_message then before assiging the smart array variable add php code above this assign and withing the function to set my_module_message = ($variable_message) for example if ($x == foo) $variable_message = 'equal to foo'; else $variable_message = 'not equal foo'; then assign: 'my_module_message' => $variable_message, I hope I understood your question and helped accordingly. Link to comment Share on other sites More sharing options...
Enrique Gómez Posted September 13, 2013 Share Posted September 13, 2013 Should I put the php code in this part, create a new php file and call it from here or what? Yes you can put the code there, or you can call some external function and then assign the result in the tpl which will be rendered into the HOOK_LEFT_COLUMN Link to comment Share on other sites More sharing options...
pedrogon Posted September 13, 2013 Author Share Posted September 13, 2013 Thanks a lot for your quick responses! I've tried El Patron's solution and works like a charm. Enrique, could you please give me an example of what would be the code for calling a external function and assigning it? (or a link to the relevant documentation) P.S.: Curious, 3 spanish speakers talking in the english forum... Link to comment Share on other sites More sharing options...
El Patron Posted September 13, 2013 Share Posted September 13, 2013 jajaja..two Spanish speakers...yo soy malo hablo espanol...but I have houses in Colombia and Spain. as for your question, here is an example of obtaining a price where Tools is the classand displayPrice is the funciton within Tools $this->smarty->assign(array( 'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false), Link to comment Share on other sites More sharing options...
Enrique Gómez Posted September 13, 2013 Share Posted September 13, 2013 I was about to put a similar example.... The Autoload class makes available the php code in /classes and /controllers folder (and override folders) so you have available the utility static methods of Tools class. But you can also import your classes with for example require_once( _PS_MODULE_DIR_ . 'your_module_folder/your_module_subfolder/init.php'); Link to comment Share on other sites More sharing options...
Enrique Gómez Posted September 13, 2013 Share Posted September 13, 2013 P.S.: Curious, 3 spanish speakers talking in the english forum... We can always take a "relaxing coup of cafe con leche" Link to comment Share on other sites More sharing options...
El Patron Posted September 13, 2013 Share Posted September 13, 2013 ave maria...I have not had a good cafe con leche since I left Bembibre. Link to comment Share on other sites More sharing options...
pedrogon Posted September 17, 2013 Author Share Posted September 17, 2013 Jajaja, good one Enrique. Did you knew that they have registered it as a trademark and opened an online store only for products with this phrase!!?? http://www.antena3.com/noticias/sociedad/hija-exalcalde-madrid-solicita-registrar-relaxing-cup-cafe-leche_2013091400021.html Thanks for your examples! Marking this as solved. 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