Adding new curreny to opencart
A great topic!
Adding a new currency to OpenCart is a relatively straightforward process. Here's a step-by-step guide to help you through it:
Prerequisites:
- You have a basic understanding of OpenCart and its directory structure.
- You have a new currency code (e.g., "XAF" for Central African CFA Franc) and its corresponding symbol (e.g., "₣").
Step 1: Create a new currency file
In the catalog/language/english/currency
directory (or the language directory of your choice), create a new file with the same name as your new currency code (e.g., xaf.php
). This file will contain the currency's details.
Step 2: Define the currency details
In the xaf.php
file, add the following code:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Currency_xaf extends Currency {
public $code = 'XAF';
public $symbol = '₣';
public $symbol_left = '₣ ';
public $symbol_right = ' ';
public $value = 655.957;
public $value_text = 'Central African CFA Franc';
}
Here, we're defining the currency code, symbol, and other details. You can adjust these values as needed.
Step 3: Update the currency list
In the catalog/model/localization/currency.php
file, add the following code:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Model_localization_currency extends Model {
public function get_currencies() {
$currencies = array(
'XAF' => 'Central African CFA Franc',
// Add other currencies here...
);
return $currencies;
}
}
This code updates the currency list to include your new currency.
Step 4: Update the currency conversion rates
In the catalog/model/localization/currency.php
file, add the following code:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Model_localization_currency extends Model {
public function get_conversion_rates() {
$conversion_rates = array(
'XAF' => array(
'EUR' => 0.0015,
// Add other conversion rates here...
),
);
return $conversion_rates;
}
}
This code updates the currency conversion rates to include your new currency.
Step 5: Clear the cache
To ensure that the changes take effect, clear the OpenCart cache by going to System > Settings > Cache
and clicking the "Clear cache" button.
Step 6: Test the new currency
Log in to your OpenCart admin panel and go to System > Settings > Currency
. You should see your new currency listed. You can test it by setting it as the default currency and checking that the prices are displayed correctly.
That's it! Your new currency should now be added to OpenCart.