Jump to content

No more presence of $currency Smarty object


Recommended Posts

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.

Link to comment
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

Link to comment
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. 🙄

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
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;

}

 

Link to comment
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}
Link to comment
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.

 

Link to comment
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.

Link to comment
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

Link to comment
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');

 

Link to comment
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.

Link to comment
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.

Link to comment
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.
 

Link to comment
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.

×
×
  • 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