Jump to content
bellafronte

No more presence of $currency Smarty object

Recommended Posts

debugging with Smarty debug Console I notice that $currency Smarty object is no more present on v8

844139788_Screenshot(5).png.ec179f09b6f3677037825e48c192baa9.png

on v7 this is accessible on any output hook as $params['currency'] array.

WHMCS 8 is manipulating the current currency in another way?

Share this post


Link to post
Share on other sites

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...

  1. if logged in, use assigned currency..
  2. if not logged in and if session currency exists, use that.
  3. use default currency.

though the $currency variable not existing is going to cause hassle for many existing solutions.

Share this post


Link to post
Share on other sites
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...

  1. if logged in, use assigned currency..
  2. if not logged in and if session currency exists, use that.
  3. 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 😕 

Screenshot from 2020-10-02 01-06-28.png

Share this post


Link to post
Share on other sites
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. 🙄

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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;

}

 

Share this post


Link to post
Share on other sites
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.

OM8UW5V.png

{$currency.id}

Share this post


Link to post
Share on other sites
14 hours ago, brian! said:

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.

OM8UW5V.png


{$currency.id}

Greetings @Brian

this works if you have a GET parameter on the cart.php file

However if you go directly to cart.php the variable $currency disappears.

Can you try again to see the list of products without any parameter?

I spent several hours last night trying to figure this out to no avail.

 

Share this post


Link to post
Share on other sites
17 hours ago, bellafronte said:

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;

}

 

Hello, @bellafronte

I've tried been solution, however, as expected, I don't get anything inside cart.php in whmcs 8.0.2

I will probably have to contact whmcs to review why they have removed this very important variable.

Share this post


Link to post
Share on other sites

After thinking a lot, I think I found the solution.

I have created the following hook, which allows to obtain the currency that is in use or active in WHMCS V8.0.2

 

<?php
add_hook('ClientAreaHeadOutput', 1, function($vars) {
	$currencyid = (isset($_SESSION["currency"]) ? $_SESSION["currency"] : "");
	if (empty($_SESSION["uid"])){
		$currency = getCurrency($userid, $currencyid);
	}
	else {
		$currency = getCurrency($userid);
	}
	$smartyvalues["currency"] = $currency;
	var_dump($smartyvalues["currency"]);
  
});

 

731735199_descarga-2020-10-15T023516_651.thumb.png.7b51f44ac871077d0629442db8fe8fcd.png

Share this post


Link to post
Share on other sites

and if you want to use the variable: {$currency.code} in your smarty template in whmcs v8 just add the following hook and you can use it anywhere.

currency_active.php

<?php 
function hook_currency_active($vars)
{
    $currencyid = (isset($_SESSION["currency"]) ? $_SESSION["currency"] : "");
    if (empty($_SESSION["uid"])) {
        $currency = getCurrency($userid, $currencyid);
    } else {
        $currency = getCurrency($userid);
    }
    $smartyvalues = array();
    $smartyvalues["currency"] = $currency;
   return $smartyvalues;
}

add_hook('ClientAreaPage', 1, 'hook_currency_active');

 

Share this post


Link to post
Share on other sites

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...

gwMEskW.png

<?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.

Share this post


Link to post
Share on other sites
6 hours ago, brian! said:

Hi Jesus,

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 ??

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). 🙄

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...

gwMEskW.png


<?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.

Hello,

in our case we do not allow geolocation of coins when the user has logged in or is connected.

In other words, this solution works if the client is not connected.

In our case, that solution works.

Share this post


Link to post
Share on other sites
On 10/15/2020 at 11:44 AM, brian! said:

Hi Jesus,

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 ??

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). 🙄

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...

gwMEskW.png


<?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.

This works fine.

However I made a ticket to whmcs, because I wanted to get a clear answer directly from whmcs to solve this, and the answer was very absurd.

They said you had to use jquery to achieve this. It was very silly to ask. (the support answer is very ridiculous and absurd).

906668776_descarga-2020-10-17T000153_992.thumb.png.cef89fe8c012e24df33cbb2f2df59fed.png

It is also very frustrating to know that whmcs has no clear answer on how to solve this.

I am quite disappointed this time from whmcs.

Also, I haven't gotten whmcs to answer this topic either.

Very bad whmcs. At this point I'm not sure if it's a good idea to use whmcs v8.
 

Share this post


Link to post
Share on other sites
6 hours ago, JesusSuarz said:

However I made a ticket to whmcs, because I wanted to get a clear answer directly from whmcs to solve this, and the answer was very absurd.

"this is just an example and not tested by any means" - wtf ?

for the cost of WHMCS support, i'd hope for better than posting random nonsense hooks that don't work... and even if it did work, I don't think it would meet your intention on how to use the variable in the template.

it doesn't bother me that the serf at Support might not have explained why the variable no longer exists (he probably doesn't know the reason) - but I would expect someone from WHMCS to justify/explain it here... maybe it will be quietly fixed in v8.0.3 - I assume with the number of hotfixes being released and all the other new bugs, it will only be a matter of time before there is another maintenance release.

Share this post


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.

Guest
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.


  • Similar Content

    • By HancoEuropa
      Hello!
      I'm using Lang::trans within a php hook for EMailPreSend.
      I set 'credited' in each language override file:
      $_LANG['locale'] = "en_GB"; $_LANG['credited'] = "has been credited"; and
      $_LANG['locale'] = "ro_RO"; $_LANG['credited'] = ": tranzacția a fost creditată";
      Then, in the hook:
       
      $merge_fields = []; $paymentMethodTitle = "Bank Transfer"; $newSubject = $paymentMethodTitle.' '.Lang::trans('credited'); $merge_fields['custom_subject'] = $newSubject; $vars = array_merge( $vars, $merge_fields ); return $vars; In the Email Template, the subject is {$custom_subject}, which shows $newSubject variable just fine.
      But I guess Lang::trans doesn't use the client's language.
      The email template (body) uses the client's language without issue, but ... how in the world do I get Lang::trans in EMailPreSend to use the client's language?
      I just want the client's language to be used when sending the client an email (call me silly!). 
      Thanks for any clues!
       
       
    • By mfoland
      Hello,
       
      I made a Square Gateway, which is in the Marketplace. The issue right now, is it's coded with PHP, and has to rely on allowing it to run with the php smarty tags, which aren't recommended. Is there an alternative way to avoid Smarty PHP tags?
       
      Thanks!
    • By grapyhost
      Hello everyone, Hope you all doing good.
      as WHMCS update with version 7.7 and its included crypto currency payments. So i am trying to configure it in my whmcs grapyhost.  but i am facing some issue or maybe a bug. check below screenshot.

      I have added Bitcoin currency and trying to fill up product with respective crypto prices. but its not accepting value.  as one product monthly annual price is $16.83 so it will be 0.0047 BTC . but its not accepting btc value. Please suggest some to fix it.
       
      Thanks
      Madan
       
    • By zstergios
      Seems there is currency issue.
      Latestly I have added 3rd currency USD (ID:5)
      Gateway has Convert to EUR
       
      The transaction marked has got currency ID=0
      http://prntscr.com/kyxm4l
      I think should be 5 ID
      I have whmcs 7.6.1
    • By So, who am I ?
      Hello
      I'd like to sell domains with different price and currency for customers who visit from outside my country.
      I'm thinking to use OrderDomainPricingOverride hook to change price for non local customers, I plan to differ local and non local customers by their IP. But before I start, thought to ask here, maybe there's a better built in way of doing it that I couldn't find.
      I see I can add another currency to WHMCS but it says:  Customers who visit your site can then choose to shop in their local currency.
      I don't want customers to have to choose currency, I want local ones to shop with local currency and non local one with non local currency. I still can differ it manually by IPs I know, just want to know if WHMCS has some extra features for it that I can use.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated