Jump to content

Calling a function of a class module


freuxbang
 Share

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.php
Expect to receive data from the function containsProduct () to elaborarmi data

class MyClasse {

public static function getMyData($id_product){

//code...

return;

}

}

 
override/classes/Cart.php

This function is launched when you click on Add to Cart
In 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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More