Use functions in different modules

Hello everyone,

i have two custom modules that export some data to csv. In some parts they are identical, for example there are many functions that both modules need. So to avoid double-code my first idea was to extend the module from a module/class that holds the functions.

Then i saw the modules/functions.php file.

I would prefer method 1 tho.

What would be the best way for doing this in OXID?

Depends on what this functions are doing, can you be a bit mor precise ?

regards

Rafael

for example number / money formatting, get charset, mainly functions used in oximex.php for the lexware export

ok charset you can get via
$oxConfig::getInstance()->isUTF();

Numberformating:
First getting Currency object, then you can use it for formating.


$sName = "USD"; // Name of Currency entered in backend
$oCur = $oxConfig::getInstance()->getCurrencyObject( $sName );
$oCur->rate; // Exchange rate;
$oCur->dec;     // decimal seperator
$oCur->thousand; // thounsands seperator
$oCur->sign;     // currency sign
$oCur->decimal;  //decimal precision

thanks for your advice, rafael. but it would be very nice to know what would be the best way if i have some custom (own) functions that i want to use in 2 or more different modules.

I just wanted to show you that you do not need to allways reinvent the wheel :wink:
but you can have a look at the oxcmp classes or the oxutils: http://docu.oxid-esales.com/CE/sourcecodedocumentation/4.5.0.34568/

Regards

Rafael

Thanks, Rafael. Seems that i should take a closer look at oxid own things.

Could i extend a module (like mymodule => mysecondmodule) or instead of using mymodule_parent just use a class with all functions i need in it? (just an idea)

If you insist to have your own class you can create one and put it into the /core folder.
just extend something like oxI18n.
Definition:


class yourClass extends oxI18n
{
...
}

Call:


//public functions
$oClass = oxNew('yourClass');
$oClass->yourFunction(); 

//or static functions
yourClass::yourFunction(); 

But it is a bit of bad habbit in an MVC Enviroment.

Regards

Rafael

you can extend modules, but not the way you describe it, and there is actually no need for extending modules.

e.g. you’ve got a car, “car” is a class, and it can drive, tun around, switch the lights on and off.
now you can get a module “tuning” which contains some additional functions like playing music, some lowrider funtionality but it can also make your car drive faster (its called function override)

technically this module says to the oxid shop “take all my functions and put them into the parent class”, you have to write inside the module section in backend which class you want to exted, like “myCar => tuning”.

you can create an own class with all your functions, but the shop’s module system is already the easiest way to keep an eye on changes you have done in the shop and also keep them after a shop update.