Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Let user select their own default currency


chrishamblin

Recommended Posts

Hi All.

 

One of our sales team wanted people to be able to select their own default currency, so I played around a bit and have come up with a solution.

 

I don't know if this is good enough to be considered a Contribution, so I thought I'd post it on the forum instead.

 

 

===

 

It works by adding another currency selection box to the Account_edit page. This choice is then stored in the database.

When the user logs in from that point, the database will be checked, and if a preference is selected, it will be applied.

 

If there is no option selected and the logged in user changes the currency, they get an info box at the top of the page letting them know that they can make this change permanently.

 

I think it's quite simple and logical.

 

 

Any questions or problems, please let me know.

 

Chris.

 


Add option to set currency in account settings in Oscommerce

BACKUP your store and database before doing this, so if anything goes wrong you can easily revert back to the fully working copy.


#############

Steps:

1: BACKUP
2: Execute SQL command to add a new column to the “customers” table
3:  Edit the following files: 
catalog/account_edit.php
catalog/includes/classes/currencies.php
catalog/includes/header.php


###############
SQL Command

SQL code :
ALTER TABLE `customers` ADD `customers_currency`  VARCHAR( 128 ) ;


###############
In “catalog/account_edit.php”

After (around line 30):

   $fax = tep_db_prepare_input($HTTP_POST_VARS['fax']);

Add:

   $currency = tep_db_prepare_input($HTTP_POST_VARS['currency']);

-----------

After (around line 94):

       ‘customers_fax' => $fax,

Add:

  'customers_currency' => $currency);

Ensure that you change the “);” to a “,” at the end of “$fax”.

-----------


After (around line 233):

                   <td class="main"><?php echo tep_draw_input_field('fax', $account['customers_fax']) . ' ' . (tep_not_null(ENTRY_FAX_NUMBER_TEXT) ? '<span class="inputRequirement">' . ENTRY_FAX_NUMBER_TEXT . '</span>': ''); ?></td>
                 </tr>

Add:

<!-- add to set currency -->				  

                 <tr>
                   <td class="main" valign="top"><?php echo "Please select a<br>default currency:"; ?></td>
                   <td class="main">
				<?php
reset($currencies->currencies);
$currencies_array = array();
       while (list($key, $value) = each($currencies->currencies)) {
               $currencies_array[] = array('id' => $key, 'text' => $value['title']);
       }

$hidden_get_variables = '';
reset($currencies->currencies);

while (list($key, $value) = each($currencies->currencies) ) {
       if( $currency == $key )
               $hidden_get_variables .= $key;
       }
$info_box_contents = array();

echo tep_draw_pull_down_menu('currency', $currencies_array, $currency);
				?>
				</td>
                 </tr>

<!-- eof to set currency -->



###############
In “catalog/includes/classes/currencies.php”

Right at the top, just after:
 Copyright (c) 2008 osCommerce

 Released under the GNU General Public License
*/

Add:

if (tep_session_is_registered('customer_id')) {
$set_cust_id = $customer_id;
$get_cust_currency = tep_db_query("select customers_id, customers_currency  from " . TABLE_CUSTOMERS . " where customers_id = ". $set_cust_id);
while ($find_set_currency = tep_db_fetch_array($get_cust_currency)){
$picked_up = $find_set_currency['customers_currency'];

}
// echo $picked_up;
if (!is_null($picked_up)){
$currency = $picked_up;
}
}



###############
In “catalog/includes/header.php”

At the top, just under:

 if ($messageStack->size('header') > 0) {
   echo $messageStack->output('header');
 }
?>

Add:


<?php if (isset($_GET["currency"]) && is_null($picked_up) && tep_session_is_registered('customer_id')) { ?>
<div class="messageStackSuccess">You can set your currency permanently in your <u><a href="<?php echo tep_href_link('account_edit.php'); ?>">account settings</a></u><?php echo $picked_up; ?></div> 
<?php } ?>


##############

And you’re done.

Now the customer has the option of setting their own default currency via the “Account Information“ section.

If they haven’t selected a currency in their settings (and are logged in) and do so using the info box, a message appears at the top of the screen letting them know that they can do so.






Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...