Guillaume 0 Posted March 17 Share Posted March 17 Hi, I've developped a plug-in for Systempay as a payment method. Nothing too fancy here, the form they expect is fairly standard (currency code, amount, etc.) However, I want to offer the user the possibility to change the currency (if the website of course allows it). I try to retrieve the exchange rate from Cubecart's admin with: $exchange_rate = tpl_vars['CURRENT_CURRENCY'] (see gateway.class.php line 97) But that value is always empty. I believe I am calling the variable in a wrong manner. But could anyone guide me on how to retrieve it? Cheers, Guillaume SystempayCurrencyIssue.zip Quote Link to post Share on other sites
bsmither 1,481 Posted March 17 Share Posted March 17 Please try: General: $myVar = $smarty->getTemplateVars('foo'); Specific: $exchange_rate = $GLOBALS['smarty']->getTemplateVars('CURRENT_CURRENCY'); However, be cautious because CubeCart might not assign a value to CURRENT_CURRENCY until after the gateway code is executed (class is instantiated or method called). Quote Link to post Share on other sites
Guillaume 0 Posted March 18 Author Share Posted March 18 Hi, Cheers for the advice. Unfortunately the first line prevents my soft from executing, while on the second one, the variable $exchange_rate ends up being empty. Is there any thing I shall do beforehand (e.g. any import I shall do)? In regards to your last remark, I actually intend to use this piece of code in the gateway code itself. So I'm not sure if that's wise. I'm guessing that in the cart attributes, we should have both the default currency and the currency the user chose, no? Because that's displayed to the user even before we execute any payment call? Thanks in advance, Guillaume Quote Link to post Share on other sites
bsmither 1,481 Posted March 18 Share Posted March 18 The first line of code is from the Smarty documentation. The Smarty docs use the established variable $smarty to hold the Smarty class instantiation in its examples. CubeCart uses $GLOBAL['smarty'] instead. The gateway class is given the session's user details, the Cart's basket, and not much else. To see this, in admin, Store Settings, Advanced tab, enable Cubecart's debug mode, followed by your local public IP address in the next field (www.showmyip.com). Now, at the bottom of every page, there is a grey section of debug info. You will see the SESSION, __client, currency. It will also include the __basket details. CubeCart manages everything using the currency that is set as the default in Store Settings. For every place that the visitor's chosen currency is to be displayed, CubeCart calls $GLOBALS['tax']->priceFormat() which calculates the exchanged value along with the necessary characters for that currency. Quote Link to post Share on other sites
Guillaume 0 Posted March 18 Author Share Posted March 18 Hi, I actually manage to display the currency selected by the customer with: $GLOBALS['session']->get('currency', 'client') Would you know with which function I could call the corresponding exchange rate from that currency to the default one (i.e. the rate which is displayed in my Cubecart settings)? Guillaume Quote Link to post Share on other sites
Guillaume 0 Posted March 18 Author Share Posted March 18 Enclosed are the logs I am getting in the debug mode. I can indeed see the GBP currency retrieved. However, I see no trace of the exchange rate. My assumption is that this currency characteristic (the exchange rate is not retrieved unless my piece of software especially requests this). Any hint on how I could retrieve it? Logs multi-currency.txt Quote Link to post Share on other sites
Guillaume 0 Posted March 19 Author Share Posted March 19 Hi, I did what you mentioned, activating debug mode and checking the logs. I have tried instanciating the following: $GLOBALS['smarty']->getTemplateVars('CURRENT_CURRENCY'); tpl_vars['CURRENT_CURRENCY']->value['exchange_rate']; $CURRENT_CURRENCY[value]; //as I saw from the logs (when updating the exchange rate), that exchange rate variable goes in a field called value All of which are empty... When I try $GLOBALS['tax']->priceFormat(), my file does not execute. The good news is that I manage to retrieve the currency the user selected, in $GLOBALS['session']->get('currency', 'client'). But any hint how I could extract the exchange_rate from there? Guillaume Quote Link to post Share on other sites
bsmither 1,481 Posted March 19 Share Posted March 19 I will look into this very soon. If you haven't already, please create the error log: https://forums.cubecart.com/topic/51550-how-to-create-the-error-log/ Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.