bellafronte Posted October 2, 2020 Share Posted October 2, 2020 debugging with Smarty debug Console I notice that $currency Smarty object is no more present on v8 on v7 this is accessible on any output hook as $params['currency'] array. WHMCS 8 is manipulating the current currency in another way? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 2, 2020 Share Posted October 2, 2020 if/when the currency is changed, it's still in the session array - so that bit at least hasn't changed... though you can no longer access the session array in Smarty without first updating the security policy - which is a total pain. I assume the logic is still... if logged in, use assigned currency.. if not logged in and if session currency exists, use that. use default currency. though the $currency variable not existing is going to cause hassle for many existing solutions. 1 Quote Link to comment Share on other sites More sharing options...
bellafronte Posted October 2, 2020 Author Share Posted October 2, 2020 2 hours ago, brian! said: if/when the currency is changed, it's still in the session array - so that bit at least hasn't changed... though you can no longer access the session array in Smarty without first updating the security policy - which is a total pain. I assume the logic is still... if logged in, use assigned currency.. if not logged in and if session currency exists, use that. use default currency. though the $currency variable not existing is going to cause hassle for many existing solutions. Thanks @brian! so far v8 just give me headache 😕 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 2, 2020 Share Posted October 2, 2020 3 minutes ago, bellafronte said: so far v8 just give me headache 😕 don't worry - everyone's having a collective migraine trying to get their heads around this nonsense. 🤕 the session cart array no longer exists, so every $smarty.session.cart solution that's ever been posted will now fail... oh what fun. 🙄 3 Quote Link to comment Share on other sites More sharing options...
bellafronte Posted October 14, 2020 Author Share Posted October 14, 2020 3 hours ago, JesusSuarz said: this is very unfortunate, Now I don't know what to do, this is causing me a lot of problems with several of my plugins. any solution? I had a long time trying to look for the variable $ currency everywhere, It is not in the session variable, neither in the smarty debug, nor is it inside the $ vars variable In other words I don't see any way to get the variable for the currency that is in use. You will need to build your own currency checker, here a example for hooks function getUserCurrencyCode($params) { $currencyId = false; $currencyCode = false; if ($params['loggedin'] && isset($params['clientsdetails']) && is_array($params['clientsdetails'])) { $currencyId = $params['clientsdetails']['currency']; foreach ($params['currencies'] as $c) { if ($c['id'] === $currencyId) { $currencyCode = $c['code']; } } return $currencyCode; } else if(isset($_SESSION['currency'])) { $currencyId = $_SESSION['currency']; foreach ($params['currencies'] as $c) { if ($c['id'] === $currencyId) { $currencyCode = $c['code']; } } return $currencyCode; } else { foreach ($params['currencies'] as $c) { if ($c['default'] === 1) { $currencyCode = $c['code']; } } return $currencyCode; } return $currencyCode; } 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 14, 2020 Share Posted October 14, 2020 2 minutes ago, bellafronte said: You will need to build your own currency checker, here a example for hooks you do realise that in v8.0.2, the $currency values exists again - so probably no need for a hook. 🙂 it's a currency object now rather than the previous array, but you could still access it's values in hooks or Smarty if required. {$currency.id} 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 15, 2020 Share Posted October 15, 2020 Hi Jesus, 9 hours ago, JesusSuarz said: Can you try again to see the list of products without any parameter? you're right. ✔️ this is stupid - either it should be there all the time, or not there at all... how did anyone at WHMCS not see this during their internal testing ?? 6 hours ago, JesusSuarz said: I will probably have to contact whmcs to review why they have removed this very important variable. you should do that - i'd like to hear the explanation of why it's not there on all cart pages (as it has been for the last decade or however long). 🙄 4 hours ago, JesusSuarz said: After thinking a lot, I think I found the solution. sadly, I don't think it works. 🙁 if I log in as a client with a non-default currency (RON), then your hook gives the wrong results... <?php # Cart Currency Hook v1.0 # Written by brian! use WHMCS\Database\Capsule; function cart_currency_hook($vars) { $client = Menu::context('client'); if ($client) { $currencydb = Capsule::table('tblcurrencies')->where('id',$client->currencyId)->first(); } elseif (isset($_SESSION["currency"])) { $currencydb = Capsule::table('tblcurrencies')->where('id',$_SESSION["currency"])->first(); } else { $currencydb = Capsule::table('tblcurrencies')->where('default','1')->first(); } $currency = json_decode(json_encode($currencydb),true); return array ("currency" => $currency); } add_hook("ClientAreaPage", 1, "cart_currency_hook"); i'd be tempted to make it a ClientAreaPageCart hook so that it doesn't run outside of the cart - but if it had to run outside of the cart, then i'd suggest limiting on which pages it runs as currently it will run for everyone on every client area page. also, perhaps check if $currency already exists before returning it - although in your case, where I suspect you'd prefer to always access the array as an array and not an object, you might want to always return your array. and if you read the v8 docs, $client->currencyId isn't listed now as a valid string - I only know about it from the v7 docs and previous use of it... and it still works (though if it didn't there are alternatives).... so even the v8 class docs might be incomplete... oh what fun. if you wanted to take bellafronte's method of querying the currencies array rather than making one query to the database, then... <?php # Cart Currency Hook (No Capsule Fatabase Calls) v1.0 # Written by brian! function cart_currency_hook($vars) { $client = Menu::context('client'); $currencies = $vars['currencies']; if ($client) { foreach ($currencies as $key => $value) { if ($currencies[$key]['id'] == $client->currencyId) { $currency = $currencies[$key]; } } } elseif (isset($_SESSION["currency"])) { foreach ($currencies as $key => $value) { if ($currencies[$key]['id'] == $_SESSION["currency"]) { $currency = $currencies[$key]; } } } else { foreach ($currencies as $key => $value) { if ($currencies[$key]['default'] == '1') { $currency = $currencies[$key]; } } } return array ("currency" => $currency); } add_hook("ClientAreaPage", 1, "cart_currency_hook"); I don't doubt the above code could be optimised, but either solution should work until WHMCS get their act together on this. 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.