ChrisTERiS Posted May 21, 2017 Share Posted May 21, 2017 Hello, I'm using the code below for multi currency: $currencyData = $_SESSION["currency"]; $license["price"] = formatCurrency($license["price"],$currencyData); The code works in the meaning that changed currency Prefix and currency Suffix but don't updates the number. The price is MySQL format: `price` DECIMAL(10,2) NOT NULL DEFAULT '0.00', and in database appears correct. Any idea on what's going wrong? Thank you Chris - - - Updated - - - ......Addition...... I've a black thought that this function works only for whmcs products and the only work that it does is to change prefix, suffix and getting the price from the product database for that currency. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 22, 2017 Share Posted May 22, 2017 update the number in what sense? it just updates a given value into a currency format - it's not querying any tables to get the price for a product in that currency, it's just formatting the given price. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted May 22, 2017 Author Share Posted May 22, 2017 https://www.teriakis.com/cart.php Try to change the currency. The prefix/suffix are changing, the number stays the same. Even the decimal separator changes. Which guarantees that the value is numeric there. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted May 22, 2017 Author Share Posted May 22, 2017 Just found this https://forum.whmcs.com/showthread.php?53958-formatCurrency()-not-working I'll give a try. - - - Updated - - - Don't seems to work 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 22, 2017 Share Posted May 22, 2017 then perhaps the array doesn't contain both USD and EUR pricing, only one. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted May 22, 2017 Author Share Posted May 22, 2017 then perhaps the array doesn't contain both USD and EUR pricing, only one. Which array? When someone is saying pass a currency code along with a value, the function must works. Later on today I'll code my own functions and should works with any given value pair (amount, currency). I wasted already valuable time trying to figure out how the "blocked" WHMCS functions are working. As you seen in the link before, someone else had the same problem 3 years ago. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 22, 2017 Share Posted May 22, 2017 I was thinking specifically of the $products array... if you had a product that was priced in 2 currencies, the array is recalculated during a change in currency from the selector... so when currency is USD, it's using the USD prices; when you change it to EUR, it's using EUR pricing. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted May 22, 2017 Author Share Posted May 22, 2017 (edited) I was thinking specifically of the $products array... if you had a product that was priced in 2 currencies, the array is recalculated during a change in currency from the selector... so when currency is USD, it's using the USD prices; when you change it to EUR, it's using EUR pricing. No, I don't have 2 prices. And the documentation does not says anything about having array with 2 or more prices. Anyway, as I said, I already waste lot of time for tests and posts. I'll make my own function and much more flexible: getCurrency($amount,$currency,$prefix,$suffix) With the last 2 parammeters I can show/hide prefix/suffix depending to my needs. Edited May 22, 2017 by ChrisTERiS Typo 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 22, 2017 Share Posted May 22, 2017 No, I don't have 2 prices. And the documentation does not says anything about having array with 2 or more prices. Anyway, as I said, I already waste lot of time for tests and posts. I'll make my own function and much more flexible:getCurrency($amount,$currency,$prefix,$suffix) With the last 2 parameters I can show/hide prefix/suffix depending to my needs. if you're in the cart, you'll already have access to $currency which has all that information already. and I see what you mean about it not having two prices - your products have a visual price, and not multiple prices in the usual way that a normal product would . 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted May 22, 2017 Author Share Posted May 22, 2017 https://www.teriakis.com/cart.php Select USD and then click or any product. The function works fine with the function using mysqli . Let's see how it will be possible to work (or not) in the homepage and the hook. - - - Updated - - - For those who want to use this function: // ####################################################################### // ############################ Exchange Currency ###################### // ####################################################################### function getExchange($amount,$currency,$prefix,$suffix) { global $db, $CFG, $LANG; $sql = mysqli_query($db,"SELECT * FROM tblcurrencies WHERE id=$currency ORDER BY id ASC LIMIT 1"); $rlt = mysqli_fetch_assoc($sql); // New Amount $_amount = $amount * $rlt["rate"]; // Prefix if ($prefix == 1) { $_prefix = $rlt["prefix"]; } else { $_prefix = ''; } // Suffix if ($suffix == 1) { $_suffix = $rlt["suffix"]; } else { $_suffix = ''; } // Format if ($rlt["format"] == 1) { $_format = '1234.56'; $thousands_seperator = ''; $decimals_seperator = '.'; $decimals = 2; } if ($rlt["format"] == 2) { $_format = '1,234.56'; $thousands_seperator = ','; $decimals_seperator = '.'; $decimals = 2; } if ($rlt["format"] == 3) { $_format = '1.234,56'; $thousands_seperator = '.'; $decimals_seperator = ','; $decimals = 2; } if ($rlt["format"] == 4) { $_format = '1,234'; $thousands_seperator = ','; $decimals_seperator = ''; $decimals = 0; } return $_prefix.number_format($_amount, $decimals, ''.$decimals_seperator.'', ''.$thousands_seperator.'').' '.$_suffix; } You can get the $currency value from $_SESSION["currency"] 0 Quote Link to comment Share on other sites More sharing options...
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.