freuxbang Posted February 16, 2015 Share Posted February 16, 2015 Hi, how can I call a function of a class of a module? To avoid entering the same code in multiple pages php I would call a function located within a module. example: modules/pippo/controllers/front/BL.php class BLController4 { public static function getMpProduct($id_product) { ..... } } In the class PaymentModule.php I want to draw the function result getMpProduct() What should I write? Thank you Link to comment Share on other sites More sharing options...
bellini13 Posted February 16, 2015 Share Posted February 16, 2015 put the function in your main module, and then call it from your front controller. Link to comment Share on other sites More sharing options...
freuxbang Posted February 16, 2015 Author Share Posted February 16, 2015 you can give me an example? I did not understand well thank you Link to comment Share on other sites More sharing options...
bellini13 Posted February 16, 2015 Share Posted February 16, 2015 moved the function from BLController4 to your modules main class public static function getMpProduct($id_product) { Then in your BLController4 front controller, you can execute the function $this->module->getMpProduct Link to comment Share on other sites More sharing options...
freuxbang Posted February 18, 2015 Author Share Posted February 18, 2015 In which folder should I move the function getMpProduct ? ____________________________ I was also trying to find a solution for another operation that I have to play. While sending the product to your cart and saving in the table ps_cart_product I wish that would save the form data in a database table created by me. Doing research I saw that just insert the module function "hookActionCartSave". Just before saving this data, I should recover other values located in the "containsProduct" within classes/Cart.php I could very well enter an INSERT sql inside the function classes/Cart.php or override/classes/Cart.php and solve the problem, but I would avoid putting extra code to these files. Would that be the module to handle all this. So I come to my question: How do I get in the function hookActionCartSave data processed within the function "containsProduct" managing everything from the module? Thank you Link to comment Share on other sites More sharing options...
freuxbang Posted February 18, 2015 Author Share Posted February 18, 2015 For now I have done so:Let me give an example by simplifying the code doing flounder only a value such as Product ID modules/mymodule/controllers/front/BL.phpExpect to receive data from the function containsProduct () to elaborarmi data class MyClasse { public static function getMyData($id_product){ //code... return; } } override/classes/Cart.phpThis function is launched when you click on Add to CartIn this example I'm only sending a value as the product id. include_once(_PS_MODULE_DIR_.'mymodule/controllers/front/BL.php'); public function containsProduct($id_product){ MyClasse::getMyData($id_product); //code... } I would like to retrieve the values that are caught in the function containsProduct only inserting the code inside the module "mymodule, and then without entering "MyClasse::getMyData($id_product);" e "include_once(_PS_MODULE_DIR_.'mymodule/controllers/front/BL.php');" inside override/classes/Cart.php . Is there a way? thank you 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