Jump to content

Retrieve numerical currency codes from Cubecart's databases?

Recommended Posts


I am currently working on developping a new gateway to interface with Systempay, and would like to make it support several currencies (provided of course, that the website of the subscriber supports it). As such, the idea would be to rely on Cubecart's currency conversion tables, and convert the amount and change the currency before approaching the gateway (Systempay). I do not want to let Systempay do the currency conversion (because if they do, any mark-up goes to them).
However, as for many gateways, it expects the numerical currency code in the request. This led me to define a table like the below, in my gateway.class.php. But I believe a more elegant manner would be to call Cubecart's reference database, if it stores it at all?

Anyone could point me to a command which would call such reference database? Or does Cubecart not have that data? It would help me getting rid of the below hardcode:

#Numeric currency calculation
        $num_currency = array(
            'EUR' => "978",
            'GBP' => "826",
            'AUD' => "036",
            'BGN' => "975",
            'BRL' => "986",
            'CAD' => "124",
            'CHF' => "756",
            'CNY' => "156",
            'CZK' => "203",
            'DKK' => "208",
            'HKD' => "344",
            'HRK' => "191")

Thanks a lot in advance for your help! Best regards,


Link to post
Share on other sites

It appears CubeCart has the ISO code for currencies in the table CubeCart_currencies.

In your code, you can instantiate a new Tax class, tell it to load the currency data for whatever you want, then ask for the 'iso' value.

So, try this:

$myTaxObject = new Tax;
$currencyISO['AUD'] = ($myTaxObject->loadCurrencyVars('AUD')) ? $myTaxObject->_currency_vars['iso'] : false;
// more work as needed

(I have not tried this.)

Link to post
Share on other sites

I've tried the above, but I am afraid my code does not compile. I have a few questions:

  • Why do we need to define a Tax object for that? Isn't it just about calling a Cubecart database with a key (e.g. "EUR") to retrieve a value ("978")?
  • In the above, what exactly disappears after the below instruction? In particular, is the $currencyIso['AUD'] still defined after that? (I have tried putting the unset at the very end of my code, but it still did not compile
  • Would we have a description somewhere of the database CubeCart_currencies? I believe I haven't in my previous soft, ever called such reference databases, so I would be interested in knowing how to do so
Link to post
Share on other sites

The tax class is a Singleton. Thus,

$myTaxObject = new Tax;

Should be:

$myTaxObject = Tax::getInstance();

In the programming school that teaches MVC principles, The Controller need not know where the data is at, or in what form, because the Model provides it. (CubeCart doesn't follow MVC exactly, but I find it is close enough.)

A call to the Database class could be made, to accomplish the same as what the Tax class did.

$currency_records = $GLOBALS['db']->select('CubeCart_currency','iso',array('code' => "AUD"));
if ($currency_records !== false) $currencyISO['AUD'] = $currency_records[0]['iso'];

If the Tax class had been instantiated just for this purpose, then unsetting it would have been good housekeeping. (As well as when PHP is shutting down, all classes are destructed.) The variable $currencyISO['AUD'] is still holding the value assigned to it.

You can examine the database structure ('schema') using common database utilities (phpMyAdmin is usually available in the hosted account's control panel, or other third-party utilities such as HeidiSQL).

Or, from the CubeCart installation package, you can look in the /setup/db/install/structure.sql file.

Unfortunately, there is no Cubecart SDK as yet.

Link to post
Share on other sites


The below worked indeed. Thanks a lot for your help, I've adapted it and added it to my code!

$currency_records = $GLOBALS['db']->select('CubeCart_currency','iso',array('code' => "AUD"));
if ($currency_records !== false) $currencyISO['AUD'] = $currency_records[0]['iso'];
Link to post
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...