Forums / Currencies & Sales Taxes, VAT, GST, etc. / Forcing default currency at checkout

Forcing default currency at checkout

Started by haroldf on 26 Nov 2015, 4:33 AM · Views: 8,155

Results 21 to 24 of 24
4 Apr 2016, 6:37 PM
#21
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,129
Plugin Contributions:
56

Forcing default currency at checkout

Aha! The issue is that the currencies' initialization doesn't take the setting "Switch To Default Language Currency?" into account on the very first access.

Try changing your store's /includes/init_includes/init_currencies.php, adding the highlighted fragment:

<?php
/**
 * initialise currencies
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
 *
 * @package initSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_currencies.php 6300 2007-05-11 15:49:41Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

// If no currency is set, use appropriate default
if (!isset($_SESSION['currency']) && !isset($_GET['currency']) ) $_SESSION['currency'] = [B](USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : [/B]DEFAULT_CURRENCY;  //-20160404-lat9-Force language currency

// Validate selected new currency, if any. Is false if valid not found.
$new_currency = (isset($_GET['currency'])) ? zen_currency_exists($_GET['currency']) : zen_currency_exists($_SESSION['currency']);

// Validate language-currency and default-currency if relevant. Is false if valid not found.
if ($new_currency == false || isset($_GET['language'])) $new_currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? zen_currency_exists(LANGUAGE_CURRENCY) : $new_currency;

// Final check -- if selected currency is bad and the "default" is bad, default to the first-found currency in order of exch rate.
if ($new_currency == false) $new_currency = zen_currency_exists(DEFAULT_CURRENCY, true);
//echo '<br />NEW = ' . $new_currency . '<br />';

// Now apply currency update
if (
   // Has new currency been selected?
  (isset($_GET['currency'])) || 

  // Does language change require currency update?
  (isset($_GET['language']) && USE_DEFAULT_LANGUAGE_CURRENCY == 'true' && LANGUAGE_CURRENCY != $_SESSION['currency']  )

) {
  $_SESSION['currency'] = $new_currency;
  // redraw the page without the currency/language info in the URL
  if (isset($_GET['currency']) || isset($_GET['language'])) zen_redirect(zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language'))));
}
?>
4 Apr 2016, 7:23 PM
#22
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Forcing default currency at checkout

Thanks lat9 ... I must need more coffee today ... I stared at that line multiple times and missed that, because the next few lines take the language into account. (But they only trigger if the language is being changed.) Good catch.

hairydog, does the suggestion from lat9 fix your situation?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

5 Apr 2016, 12:51 PM
#23
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Forcing default currency at checkout

DrByte:

hairydog, does the suggestion from lat9 fix your situation?I hope so. I've put that bit of code in, but haven't had time to remove the workaround to see if the problem is still gone. It certainly looks like the sort of thing the symptoms pointed to.

Thanks to you and lat9

5 Apr 2016, 3:49 PM
#24
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Forcing default currency at checkout

On reflection, it would be really nice to strip out all the language code entirely, so that there are no language lookups and it uses the default language regardless of sessions, settings or anything. In insular little England, I have never been asked to set up any multi-language sites.

But there again, there are lots of other bells and whistles in ZC I'd like to get rid of!