Jump to content

Get Module Name and Version (and all parameters of config.xml)


Recommended Posts


I developped two twin payment gateways which differ only by an if loop (I would have liked to avoid it, but was advised to do this way, see below link).

To better manage my if loop where the modules differ, I would like, in gateway.class.php, to retrieve the module name (as defined in config.xml) and make a condition on it. In index.tpl, I use $VAL_SELF (which isn't exactly the module name, but good enough to make a condition), but I don't see how to get such data in gateway.class.php.

Similarly, the payment provider would like me to send them the version of my module (as defined in config.xml). I would like to find a way to make that soft and not have to change it each time I publish. I tried CC_VERSION but that's the Cube Cart version, I couldn't see where to get the module version.

Thanks for any help you may bring. Cheers,



Link to comment
Share on other sites

The name of the gateway that the customer has eventually chosen to use has been stored in the CubeCart_order_summary database row for that order, and is also held in the Cart->basket array, which is retrieved by reference into the gateway class variable $this->_basket.

Your gateway class __construct() method should have:
$this->_basket =& $GLOBALS['cart']->basket;

So, within the gateway class, test for the value of $this->_basket['gateway']. But, it will be the folder name.

It seems that CubeCart does not read the gateway's config.xml file for storefront purposes. That means, as far as I can tell, your gateway will need to read its own config.xml file and process it to get the <info> sub-nodes you need. The code you can use will be based off that which you see in the admin /sources/plugins.index.inc.php script starting near line 295.


Link to comment
Share on other sites

Cheers, I guess I am struggling from the very beginning, which is, getting to the config.xml file (which is in the very same folder as the gateway.class.php I am calling it from...)

The glob function wouldn't really work for me as I have only one file. So I have tried getcwd() but it returns this: /home/clients/730d21bd55854ec4d0c02aa159bd4077/sites/www.temp-alerte.com, not exactly what I was after...

Of course I have tried simplexml_load_file("config.xml") and simplexml_load_file("/config.xml") but none worked. I'm certainly missing something very basic here.

Link to comment
Share on other sites

Since you know you are in the gateway class, you can use:

The directory of the file. If used inside an include,
the directory of the included file is returned. This
is equivalent to dirname(__FILE__). This directory name
does not have a trailing slash unless it is the root


$objXML = simplexml_load_file(__DIR__ . "/config.xml");

CubeCart starts all executions (with one or two exceptions because of extension module requirements) at either /index.php or admin_X.php. So, getcwd() will return the path to either of those two scripts, respectively. All other scripts are include() or require() into those two scripts.

Link to comment
Share on other sites

  • 2 weeks later...

Cheers, I retrieve the config version and uid with the below code - works perfectly indeed:

            $configxml = simplexml_load_file(__DIR__ . "/config.xml");
            $module_version = $configxml->info->version;
            $module_uid = $configxml->info->uid;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...