SOLVED - Currency ACL

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #66311

I'm looking for a way to restrict different currencies to different user groups.
I know, I could probably hide the currency switcher module and call /index.php?option=com_hikashop&ctrl=currency&task=update with the appropriate currency id on user login, but if there was an easier, safer and cleaner way to do this, I'd really appreciate this. If I did it my way, the user could still set up an own form to call the currency switcher and change the currency.

Thanks for any help in advance,
nik

Last edit: 12 years 1 month ago by nik.mess.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 1 month ago #66409

Hi,

You can set an ACL for the currency in HikaShop > Configuration > Access Level and restrict the currency to some groups.
Or do it in the module options.

You can use too the geolocation plugin, which will set automatically the user zone, and user currency depending on where he is.
Here are some documentation about this plugin:
www.hikashop.com/en/support/documentatio...hop-geolocation.html

Please Log in or Create an account to join the conversation.

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #66573

Sorry, I probably didn't make myself clear enough.
I'd like to let, for example, choose European customers between EUR and USD, but Japanese customers between JPY and USD. The ACL in HikaShop>Configuration is only for backend access, right?
Using the geolocation plugin would be great for restricting users to one currency, but they should still be able to choose between the currencies assigned to them, so that won't do it, either.

Please Log in or Create an account to join the conversation.

  • Posts: 82818
  • Thank you received: 13362
  • MODERATOR
12 years 1 month ago #66593

You will have to do that with payment methods.

In your payment methods you can restrict the possible currencies and the possible zone.
So you would have to have two payment plugin, one for europe and EUR/USD and another for Japan and JPY/USD.
Then, during the checkout, it will display the corresponding payment method based on the currency and address of the user.

The catch is that you can't easily duplicate payment methods. You will have to either use two different plugins, or modify the code of the payment plugin you want to use so that you can install it next to itself.
You can see an example with the paypal2 payment plugin that will do the job if you're using paypal:
www.hikashop.com/forum/4-how-to/45181-pa...a.html?lang=fr#45636

The following user(s) said Thank You: nik.mess

Please Log in or Create an account to join the conversation.

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #66832

Thank you for your input!
I'll try to do it that way and see, if it fits the conditions.

Please Log in or Create an account to join the conversation.

  • Posts: 24
  • Thank you received: 1
12 years 1 month ago #67265

As it turned out, payment methods would not really suit our needs.
The restriction should rather be based on a per-user-basis and not on zones.

Therefore, I created an own Joomla module that checks for the current currency and compares it with a custom user field:

<?php
// this script makes sure that each customer sees his currency only
// Niklaus Messerli, Sep 2012

//don't allow other scripts to grab and execute our file
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

$myDatabase = JFactory::getDBO();

// get the allowed currency for the current user
// replace this with your own custom field ⬇ (should contain ISO 4217 currency code)
$userCurrency = hikashop_loadUser(1)->user_currency;

if(!empty($userCurrency)){
	$query = "SELECT * FROM #__hikashop_currency WHERE `currency_code`='".$userCurrency."'";
	$myDatabase->setQuery($query);
	$result = $myDatabase->query();
	$currencyRow = $myDatabase->loadObject();

	// check if allowed currency and set currency are the same
	if($currencyRow->currency_id != hikashop_getCurrency()){
		// if not, set the currency accordingly
		$myApp =& JFactory::getApplication();
		$myApp->setUserState( HIKASHOP_COMPONENT.'.currency_id', $currencyRow->currency_id );
		if(isset($_SERVER["REQUEST_URI"])){
		  	$requestUri = $_SERVER["REQUEST_URI"];
		}else{
			$requestUri = $_SERVER['PHP_SELF'];
			if (!empty($_SERVER['QUERY_STRING'])) $requestUri = rtrim($requestUri,'/').'?'.$_SERVER['QUERY_STRING'];
		}
		$redirectUrl = (hikashop_isSSL() ? 'https://' : 'http://').$_SERVER["HTTP_HOST"].$requestUri;
		$myApp->redirect($redirectUrl);
		echo 'Your login was successful. Please wait while you\'re being redirected...';
	}
} // if no currency is defined, simply stay with default currency
?>

No bugs turned up so far...

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.046 seconds
Powered by Kunena Forum