Re: Different currencies/prices based on countries?

  • Posts: 8
  • Thank you received: 0
8 years 8 months ago #2384

Hi there. Firstly, great component!

I have a site where I need to setup different prices and currencies based on the customers location. E.g. If the customer is from the US, the price should be in USD, and a fixed price. If they are from the UK, it should be GBP and a fixed price (not automatically converted between the 2). Ive setup the product with the various currencies and prices and this is working perfectly.

What im wondering is if this stuff can be done automatically? E.g. integrate some geolocation code, and based on its results force a certain currency to be used throughout the site (and hide the currency selector).

Has anyone done this, or anything similar? I think i can get the geolocation stuff to work OK, but how can I force a certain currency to be used?

By the way, the shop isnt trying to rip-off customers based on their location (like Apple does), its just that this product gets taxed in certain countries and not in others.

Thanks for the help!

Cheers
Evan

Last edit: 8 years 8 months ago by ahoy. Reason: Clarify

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
8 years 8 months ago #2385

Hi,

In the menu System->Taxation, you can set tax rules limited to a certain zone for a certain product tax category at a certain tax rate. Then, in each product, you can assign tax categories. Finally, on the checkout, after the user enters his address, the system will calculate the taxes based on the address entered by the user:
www.hikashop.com/en/support/documentatio...axation-listing.html

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

  • Posts: 8
  • Thank you received: 0
8 years 8 months ago #2389

Hey nicolas, thanks for the reply.

I had a look through those sections in the config, but unfortunately its not just a tax thing. The shop is selling only 1 book, with the main market being Australia, and the second market being the UK. There are a lot of extra costs with selling the book in Australia (tax being the largest component), so the UK version will be a lot cheaper. Thats why we dont want the customer choosing currencies - if an Australian customer works out its cheaper to buy the GBP version, the store will make a loss.

So we still want multiple currencies, but we dont want the customers choosing what they purchase in - if that makes sense!

Cheers
Evan

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
8 years 8 months ago #2391

Ok. So, you said you can manage the geolocation and just want to know how to set a currency in the code.

That's easy. You can use that code:

$app =& JFactory::getApplication();
$app->setUserState( HIKASHOP_COMPONENT.'.currency_id', $currency_id );
where $currency_id is the id of the currency in System->Currencies.

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
8 years 8 months ago #2393

If you use our Business version, we actually have a geolocation library included that you can use from within hikashop:

$geoClass = hikashop::get('inc.geolocation');
			if(!empty($this->params)){
				$timeout = $this->params->get('timeout',2);
				if(!empty($timeout)) $geoClass->setTimeout($timeout);
			}
	    	$geoClass->setIP($element->geolocation_ip);
	    	$locations = $geoClass->getGeoLocation();
	    	if(empty($locations[0])){
				$errors = $geoClass->getErrors();
				return false;
	    	}

	    	$element->geolocation_latitude = $locations[0]['Latitude'];
	    	$element->geolocation_longitude = $locations[0]['Longitude'];
	    	$element->geolocation_postal_code = $locations[0]['ZipPostalCode'];
	    	$element->geolocation_country = $locations[0]['CountryName'];
	    	$element->geolocation_country_code = $locations[0]['CountryCode'];
	    	$element->geolocation_state = $locations[0]['RegionName'];
	    	$element->geolocation_state_code = $locations[0]['RegionCode'];
	    	$element->geolocation_city = $locations[0]['City'];
			$element->geolocation_created = time();

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

  • Posts: 8
  • Thank you received: 0
8 years 8 months ago #2402

Thanks nicolas - you're a legend!

I dropped the 2 lines below into the template index file and it seems to be working, but it takes a refresh for the correct price/currency to appear. Do I have to force a refresh after those 2 lines to reset the session value or something?



nicolas wrote:

Ok. So, you said you can manage the geolocation and just want to know how to set a currency in the code.

That's easy. You can use that code:

$app =& JFactory::getApplication();
$app->setUserState( HIKASHOP_COMPONENT.'.currency_id', $currency_id );
where $currency_id is the id of the currency in System->Currencies.

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
8 years 8 months ago #2404

You can use that code to redirect the page after setting the currency so that the change is taken into account directly:

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'];
					}
					$url = ((empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) != "on" ) ? 'http://' : 'https://').$_SERVER["HTTP_HOST"].$requestUri;
					$app =& JFactory::getApplication();
					$app->redirect($url);

Last edit: 8 years 8 months ago by nicolas.

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

  • Posts: 8
  • Thank you received: 0
8 years 8 months ago #2408

Thanks nicolas!

That redirect code is giving me an error (looks like an infinite loop) but im just checking all my config settings to make sure everything is setup correctly.

Cheers
Evan

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
8 years 8 months ago #2412

Yes, you of course need to do it only once... Not on every page.

For example, you can do something like that:

$app =& JFactory::getApplication(); 
$currency = $app->getUserState( HIKASHOP_COMPONENT.'.currency_id',0);
if(empty($currency)){
 //set the currency and redirect
}
This way, the code will be done only the first time the user accesses your website.

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

  • Posts: 8
  • Thank you received: 0
8 years 8 months ago #2413

Many thanks nicolas. I had done something similar but the code wasnt as clean.

Cheers
Evan

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

  • Posts: 25
  • Thank you received: 0
5 months 3 weeks ago #304129

does this get calculated with a certain [data][order] namekey? Im not seeing it recalculate when on the payment page for us. Thank you

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

  • Posts: 25
  • Thank you received: 0
5 months 3 weeks ago #304130

also will this only show on final payment page or is there a way to make it display on the products listing page?

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
5 months 3 weeks ago #304131

Hi,

I'm sorry but I don't understand what your question is about ?
What "recalculation" are you talking about ?
The geolocation is done when the user access the website, on the first page.
At that point, it get the country of the customer and can set the currency that will be used on the website at that point.

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

  • Posts: 25
  • Thank you received: 0
5 months 3 weeks ago #304191

Ive added the taxation, but on the final payment page, no recalculation on the cart price is added for the tax.

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
5 months 3 weeks ago #304193

Hi,

This subject is about the currencies/prices based on countries / geolocation.
It's not about taxes or the products listing page.

Please open new threads when you have questions unrelated to the topic.
It's confusing if you don't and the people who previously participated on this thread get notified for no reason.

Also, when you post your questions, please provide more context. A link to the page you're talking about, and/or screenshots of the problem, and/or screenshots of the settings related to the problem you have would go a long way for us to better understand what is your problem.

With your three messages here, I still don't understand what are the problems you have so I still can't provide an answer.
Please open new threads with explanations on your issues so that we can properly help you.

Last edit: 5 months 3 weeks ago by nicolas.

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

  • Posts: 25
  • Thank you received: 0
5 months 3 weeks ago #304241

Sorry I do need assistance with regional prices.

We want to offer our prices differently for different states/ postal codes in the US, How can we set that up?

We dont want to alter each product individually, just increase or decrease all prices by 10% or what ever we decide.

So in Arizona, we would have a product for $100. In Utah, same product would be $110.

We also dont want the user to know the different prices, just to appear as if its the normal price.

Thank you!

Last edit: 5 months 3 weeks ago by cworthen75.

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

  • Posts: 66586
  • Thank you received: 9792
  • MODERATOR
5 months 3 weeks ago #304248

Hi,

I don't see any way to do that right now with HikaShop.
That would require :
- to create one or several (one per state maybe ?) custom product field (via the menu Display>Custom fields) to store the prices in each product.
- to create a custom plugin which would get the state of the user based on the IP of the user (which is not always accurate) and which would reload the prices of the products before the listing of products, the product page layouts and when the cart is being loaded using the many triggers of our API: www.hikashop.com/support/documentation/6...r-documentation.html
It's clearly not a simple project even though it's not impossible. You'll have to contact a developer to work on that for you.

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

Time to create page: 0.094 seconds
Powered by Kunena Forum