Jump to content

Currency selector


JayZzz

Recommended Posts

When a domain is found to be available, a drop down menu appears on the domainchecker page under 'More info' with options for registration period and price. However, there is no option to change the currency that the prices are displayed in. Is there a way of adding a currency selector button here? If so, how?

Link to comment
Share on other sites

if you already have multiple currencies setup in admin, then there should be a dropdown below the domain prices in domainchecker.php - take a look at the demo site @ http://demo.whmcs.com/domainchecker.php

 

if it's missing, then you either don't have multiple currencies setup or you're using a modified template.

 

the code would be in domainchecker.tpl

 

{if !$loggedin && $currencies}

<form method="post" action="domainchecker.php">

<p align="right">{$LANG.choosecurrency}: <select name="currency" onchange="submit()">{foreach from=$currencies item=curr}

<option value="{$curr.id}"{if $curr.id eq $currency.id} selected{/if}>{$curr.code}</option>

{/foreach}</select> <input type="submit" value="{$LANG.go}" /></p>

</form>

{/if}

the prices, in all applicable currencies, will have to be entered into domain pricing for each tld and year period - afaik, they aren't updated with currency updates... I don't use multiple currencies, but hopefully someone will correct me if i'm wrong.

Link to comment
Share on other sites

if you already have multiple currencies setup in admin, then there should be a dropdown below the domain prices in domainchecker.php - take a look at the demo site @ http://demo.whmcs.com/domainchecker.php

 

if it's missing, then you either don't have multiple currencies setup or you're using a modified template.

 

I have this one, but it's for the domain pricing list, and it doesn't show up when a domain is available and ready to register.

 

I believe this is the relevant bit:

 

<select name="domainsregperiod[{$result.domain}]">{foreach key=period item=regoption from=$result.regoptions}<option value="{$period}">{$period} {$LANG.orderyears} @ {$regoption.register}</option>{/foreach}</select>{/if}</td>

 

This is what I'm talking about, where the 'more info' drop down menu appears when a domain is found to be available. It provides the registrant with a choice of registration periods, but no option to adjust the currency if different currencies are being used. Given that the registrant has not necessarily registered as a client yet, the default currency has not yet been set for them (which is done later in the cart), so it looks like a missed step in the program logic.

 

BTW the support developers told me: "Clients can change their currency on the checkout page, but not the domain results page of the order form I'm afraid. However we welcome suggestions for new features on our feature request system: http://requests.whmcs.com." I can't wait around for it to be implemented, as it is an essential step. Any suggestions?

Edited by JayZzz
Link to comment
Share on other sites

I have this one, but it's for the domain pricing list, and it doesn't show when a domain is available and ready to register. This is what I'm talking about, where the 'more info' drop down menu appears when a domain is found to be available. It provides the registrant with a choice of registration periods, but no option to adjust the currency if different currencies are being used. Given that the registrant has not necessarily registered as a client yet, the default currency has not yet been set for them (which is done later in the cart), so it looks like a missed step in the program logic. Any ideas on how to integrate a currency selector at this step?

apologies, I must have misread your question.

 

BTW the support developers told me: "Clients can change their currency on the checkout page, but not the domain results page of the order form I'm afraid. However we welcome suggestions for new features on our feature request system: http://requests.whmcs.com"

You can change the currency on the domain results page, but what I don't think you can do is *easily* display the options again... It might be possible, but if WHMCS say otherwise, then i'm not going to disprove them!

 

so say you have a domain for $10 USD or €20 Euro and your default currency is USD... if you search for an available domain, you'll get the dropdown "1 Year @ $10USD"... you could add a currency dropdown/button that would change it to Euros, but it wouldn't refresh the page with "1 Year @ €20 Euro", it would set the currency to Euro and continue with the cart... showing €20 as the price on the cart summary page.

 

however, instead of adding a currency selector at the stage you mention, you could add it *before* they've even entered the domain they're searching for... actually, you could easily add it to the top menu depending on your template - but that might take some minor additional coding to fix any potential conflicts.

 

anyway, for the time being, let's add a currency selector to two template files (again, this will depend on your template) - homepage.tpl and domainchecker.tpl.

 

ideally, they should be added in the same place for consistency and the code is taken from adddomain.tpl from the comparison template.

 

in homepage.tpl, i've added the following code after <div class="textcenter"> on line 8 (in domainchecker.tpl it might be line 17)

 

{if $currencies}

<div class="currencychooser">

{foreach from=$currencies item=curr}

<a href="{$smarty.server.PHP_SELF}?&currency={$curr.id}"><img src="images/flags/{if $curr.code eq "AUD"}au{elseif $curr.code eq "CAD"}ca{elseif $curr.code eq "EUR"}eu{elseif $curr.code eq "GBP"}gb{elseif $curr.code eq "INR"}in{elseif $curr.code eq "JPY"}jp{elseif $curr.code eq "USD"}us{elseif $curr.code eq "ZAR"}za{else}na{/if}.png" border="0" alt="" /> {$curr.code}</a>

{/foreach}

</div>

<div class="clear"></div>

{/if}

this will show a flag (if present in the icons dir) alongside the currency abbreviation, which is linked so that when clicked, the page will be refreshed with the currency preselected... i.e, if the page is showing a table of tld prices in one currency, clicking on another currency icon will refresh the page and display prices in the new currency.

 

the formatting might need to be played with to fit your own template design, and you can remove any unnecessary currencies and add any that you do need.

 

just for completeness, if you wanted to add it anywhere (e.g to the top menu) and to hard-code specific currencies, you just use the following code in header.tpl (or the appropriate template)...

 

<a href="{$smarty.server.PHP_SELF}?&currency=1"> USD</a>

(or whatever currency #1 is for you)... and repeat.

 

the downside I found with having them in the top menu is that if you click them during the order process, it can refresh to the wrong cart page... I know why, and it could probably be fixed either with if statements to remove the option to change currency from the top menu when on certain pages, or better passing of the current page variables... but as I said previously, I don't personally use multiple currencies.

Link to comment
Share on other sites

instead of adding a currency selector at the stage you mention, you could add it *before* they've even entered the domain they're searching for.

 

I gave your code a try, and got the selector to appear on the domain search page (my homepage). The problem is that changing the currency on the homepage doesn't flow through to the reg period selector on the next stage (i.e. the domainchecker page), which just defaults back to the base currency. So when it comes to the user selecting the reg period they want, they don't have the prices in their own currency.

Link to comment
Share on other sites

I gave your code a try, and got the selector to appear on the domain search page (my homepage). The problem is that changing the currency on the homepage doesn't flow through to the reg period selector on the next stage (i.e. the domainchecker page), which just defaults back to the base currency. So when it comes to the user selecting the reg period they want, they don't have the prices in their own currency.

it flows on my template - currencies stay as chosen... are you using a custom template?

 

also, make sure you have domain prices entered for multiple years in all currencies - if they don't exist, it will show the base currency... goto domain pricing and select the tld (e.g .com) and enter a price for 1 year in each of your currencies.

Link to comment
Share on other sites

Okay, it's working for me now. I forgot that once a client is logged in, there isn't a way of changing the currency at that point, so I had to log out first. Thanks brian! You've been a great help. Rep added.

Edited by JayZzz
Link to comment
Share on other sites

i'm glad to have helped! :)

 

for anyone else reading this in the future, if you wanted to hard code the links into the top menu (or probably anywhere else), I *think* the following code will get around the order process issues when placed in header.tpl (or the appropriate template).

 

{if ($smarty.server.REQUEST_URI|stristr:'cart.php')}
{if ($smarty.server.REQUEST_URI|stristr:'currency')}
     <a href="{$smarty.server.REQUEST_URI|replace:'currency=2':'currency=1'}"> USD</a>
     <a href="{$smarty.server.REQUEST_URI|replace:'currency=1':'currency=2'}"> EUR</a>
{else}
     <a href="{$smarty.server.REQUEST_URI}?currency=1"> USD</a>
            <a href="{$smarty.server.REQUEST_URI}?currency=2"> EUR</a>
{/if}  
{/if}
{if ($smarty.server.REQUEST_URI|stristr:'index.php') or ($smarty.server.REQUEST_URI|stristr:'domainchecker.php')}
{if ($smarty.server.REQUEST_URI|stristr:'.php?')}
             <a href="{$smarty.server.REQUEST_URI}&currency=1"> USD</a>
             <a href="{$smarty.server.REQUEST_URI}&currency=2"> EUR</a>
{else}
             <a href="{$smarty.server.REQUEST_URI}?currency=1"> USD</a>
             <a href="{$smarty.server.REQUEST_URI}?currency=2"> EUR</a>
{/if}
{/if} 

basically, the currency option would only be shown on cart.php, index.php and domainchecker.php

 

if you have more than two currencies, then you would just tweak the currency replace lines with multiple replaces... i.e for USD (or currency #1), the code would be...

 

<a href="{$smarty.server.REQUEST_URI|replace:'currency=2':'currency=1'|replace:'currency=3':'currency=1'}"> USD</a>

from my limited testing, cart.php was the only troublesome page, so if that is true, then there is the option to have it available on all pages, but treat cart.php slightly differently.

 

{if ($smarty.server.REQUEST_URI|stristr:'cart.php')}
{if ($smarty.server.REQUEST_URI|stristr:'currency')}
     <a href="{$smarty.server.REQUEST_URI|replace:'currency=2':'currency=1'}"> USD</a>
     <a href="{$smarty.server.REQUEST_URI|replace:'currency=1':'currency=2'}"> EUR</a>
{else}
     <a href="{$smarty.server.REQUEST_URI}?currency=1"> USD</a>
            <a href="{$smarty.server.REQUEST_URI}?currency=2"> EUR</a>
{/if}  
{else}
{if ($smarty.server.REQUEST_URI|stristr:'.php?')}
             <a href="{$smarty.server.REQUEST_URI}&currency=1"> USD</a>
             <a href="{$smarty.server.REQUEST_URI}&currency=2"> EUR</a>
{else}
             <a href="{$smarty.server.REQUEST_URI}?currency=1"> USD</a>
             <a href="{$smarty.server.REQUEST_URI}?currency=2"> EUR</a>
{/if}
{/if} 

i've just used standard html links in this demo, but you could use something that fits with your template design, e.g flag icons, currency icons etc.

 

btw - I could have used "strstr" instead of "stristr" as case-sensitivity doesn't seem an issue in this case.

Link to comment
Share on other sites

  • 2 months later...

I have the following in a separate custom page to allow currency change anywhere within the site without needing to check if there are other GET variables, it simply redirects the user back to the page they were on.

 

filename : curchange.php

 


<?php
define("CLIENTAREA",true);
require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");
initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);

$rurl =  $_SERVER['HOST'];

if ($_SESSION['uid']) {
 # User is Logged In - put any code you like here
} else {
if ($_GET["currency"]){
		$_SESSION["currency"] = $_GET["currency"];
		setcookie("mycurrency", $_GET["currency"], time()+60*60*24*30,"/");

		if (isset($_GET["rurl"])){
			$rurl = $_SERVER['HOST'] . $_GET["rurl"];
		} else {
			if (isset($_SERVER['HTTP_REFERER'])){
				$rurl = $_SERVER['HTTP_REFERER'];
			}
	}
}
}
header('Location: ' . $rurl);
?>

 

 

The you just need some code in your header to change currency and show the currently selected currency

 

         {if $clientsdetails.currency}
             {if $clientsdetails.currency eq 1}<a href="javascript:;" class="selected" title="Euro">EUR</a>{/if}
             {if $clientsdetails.currency eq 2}<a href="javascript:;" class="selected" title="British Pound">GBP</a>{/if}
             {if $clientsdetails.currency eq 3}<a href="javascript:;" class="selected" title="United States Dollar">USD</a>{/if}
         {else} 
             <a href="curchange.php?currency=1"{if $smarty.session.currency eq 1 or $smarty.session.currency eq ''} class="selected"{/if} title="Euro">EUR</a>
             <a href="curchange.php?currency=3"{if $smarty.session.currency eq 3} class="selected"{/if} title="Unated States Dollar">USD</a>
             <a href="curchange.php?currency=2"{if $smarty.session.currency eq 2} class="selected"{/if} title="British Pound">GBP</a>

         {/if} 

Link to comment
Share on other sites

  • 5 months later...
  • 2 weeks later...

Hi,

I am using template COMPARISON, it is a nice template but I had to deal with a lot of things missing, one of them being the currency selector in the 2nd (choose options) and 3rd steps (order summary). So, if customer didn't set the currency at the beginning at the end he/she couldn't change that.

 

Is there a way to add the currency selector to steps 2 and 3?

 

Thanks a lot for you kind help.

 

Sergio

Link to comment
Share on other sites

Hi Sergio,

 

Is there a way to add the currency selector to steps 2 and 3?

you can use the currency code from products.tpl and modify it for the other steps...

 

Step 1 - Choose Domain

 

add the following code to configureproductdomain.tpl

 

{if !$loggedin && $currencies}
<div class="currencychooser">
{foreach from=$currencies item=curr}
<a href="cart.php?a=add&pid={$pid}&currency={$curr.id}"><img src="images/flags/{if $curr.code eq "AUD"}au{elseif $curr.code eq "CAD"}ca{elseif $curr.code eq "EUR"}eu{elseif $curr.code eq "GBP"}gb{elseif $curr.code eq "INR"}in{elseif $curr.code eq "JPY"}jp{elseif $curr.code eq "USD"}us{elseif $curr.code eq "ZAR"}za{else}na{/if}.png" border="0" alt="" /> {$curr.code}</a>
{/foreach}
</div>
<div class="clear"></div>
{/if}

i've added it below line 12 (<p>{$LANG.cartproductdomaindesc}</p>) - but you can put the code virtually anywhere, so you may need to move it around to find the best location for it.

 

TRkocnJ.png

 

with Step 1, if you search for a domain and it shows the resulting prices in one currency, then you click on another currency, it will not show the same results in the new currency - you will need to search for the domain again...

 

Step 2 - Choose Options

 

add the following code to configuredomains.tpl

 

{if !$loggedin && $currencies}
<div class="currencychooser">
{foreach from=$currencies item=curr}
<a href="cart.php?a=confdomains&currency={$curr.id}"><img src="images/flags/{if $curr.code eq "AUD"}au{elseif $curr.code eq "CAD"}ca{elseif $curr.code eq "EUR"}eu{elseif $curr.code eq "GBP"}gb{elseif $curr.code eq "INR"}in{elseif $curr.code eq "JPY"}jp{elseif $curr.code eq "USD"}us{elseif $curr.code eq "ZAR"}za{else}na{/if}.png" border="0" alt="" /> {$curr.code}</a>
{/foreach}
</div>
<div class="clear"></div>
{/if}

i've added it below line 14 ({if $errormessage})

 

qMbNqiW.png

 

Step 3 - Checkout

 

add the following code to viewcart.tpl

 

{if !$loggedin && $currencies}
<div class="currencychooser">
{foreach from=$currencies item=curr}
<a href="cart.php?a=view&currency={$curr.id}"><img src="images/flags/{if $curr.code eq "AUD"}au{elseif $curr.code eq "CAD"}ca{elseif $curr.code eq "EUR"}eu{elseif $curr.code eq "GBP"}gb{elseif $curr.code eq "INR"}in{elseif $curr.code eq "JPY"}jp{elseif $curr.code eq "USD"}us{elseif $curr.code eq "ZAR"}za{else}na{/if}.png" border="0" alt="" /> {$curr.code}</a>
{/foreach}
</div>
<div class="clear"></div>
{/if}

 

i've added it below line 40 (<h2>{$LANG.ordersummary|strtolower}</h2>)

 

Blss5ad.png

 

as I mentioned earlier, you might have to move the code around to get it in the correct position for your needs.

 

I hope this answered your question! :idea:

Edited by brian!
Link to comment
Share on other sites

Thanks a lot, Brian!

 

I have added the code to the pages you mentioned and all of them show the currencies, thank you.

 

Now I have a new issue, every time I click on the currency that I want, it doesn't change the prices instead it jumps back to the first page where the products are shown, I will try to see if I can find how to fix it.

 

Once again, thanks for your kind help.

 

Sergio

Link to comment
Share on other sites

Now I have a new issue, every time I click on the currency that I want, it doesn't change the prices instead it jumps back to the first page where the products are shown, I will try to see if I can find how to fix it.

I think that might occur if your have not set prices for the domain tld in the currency you have selected.

 

for me, steps 2 and 3 were just refreshing the page rather than going back to the products page.

Link to comment
Share on other sites

I think that might occur if your have not set prices for the domain tld in the currency you have selected.

 

for me, steps 2 and 3 were just refreshing the page rather than going back to the products page.

 

I have been using WHMCS for a long time now and used the other templates with currencies without any problems at all.

 

Something has to be wrong with the template that I have, I will start it over from a clean template.

 

Thanks.

Link to comment
Share on other sites

found the error and it is a very weird one, lol.

 

I don't know why, the following code appears in my template:

{if !$loggedin && $currencies}
<div class="currencychooser">
{foreach from=$currencies item=curr}
<a href="cart.php?gid={$gid[size=+2][b]}¤cy={[/b][/size]$curr.id}={$curr.id}"><img src="images/flags/{if $curr.code eq "AUD"}au{elseif $curr.code eq "CAD"}ca{elseif $curr.code eq "EUR"}eu{elseif $curr.code eq "GBP"}gb{elseif $curr.code eq "INR"}in{elseif $curr.code eq "JPY"}jp{elseif $curr.code eq "USD"}us{elseif $curr.code eq "ZAR"}za{else}na{/if}.png" border="0" alt="" /> {$curr.code}</a>
{/foreach}
</div>
<div class="clear"></div>
{/if}

look the declaration of the currency, it shows "...}¤cy={..." instead of "...}&currency={...", I fix it and save the page and it shows right on the browser, but if I open it again to modify anything, it reverts to "¤cy", go figure. I have done a dos2unix products.tpl but it doesn't fix it the error is always there.

 

So, I have seen this and took care when I copy and paste the code to the other pages and the error replicates on them.

 

Regarding to use currencies and when clicked it return to the main selection products page, it is because the URL doesn't populate, I mean, if the page is at "/cart.php?a=confproduct&i=0" then the currency url in that page should point to "/cart.php?a=confproduct&i=0&currency=1" but instead it shows "/cart.php?gid=&currency=1" as you can see there is no gid and then when clicked it returns to main selection product page. I will configure each page to use its own url, but if you have a better way to use the same code but with the right url, please let me know.

 

Regards,

 

Sergio

Edited by Sergio
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.

  • 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