New modification - product price currency

This module allows you to specify individual items separate currency sign, then the script calculates the value of the currency by default and makes the database. For example, if I create a product with price 100, and choose currency, the euro, while the default currency I have a dollar, the price of the goods after saving the change from 100 to 126.59 at the correct rate of exchange. Currently works only in simplex mode - in other words to transfer from euros to pounds sterling will not work



Here is what you need to do:



replace whole function fn_update_product_prices by this content:



function fn_update_product_prices($product_id, $product_data, $company_id = 0)
{
$_product_data = $product_data;
$currency_modifier=db_get_field("SELECT coefficient FROM ?:currencies WHERE currency_code = ?s",$_product_data['currency_code']);
if ($currency_modifier) {
$new_product_price=$_product_data['price'] * $currency_modifier;
} else {
$new_product_price=$_product_data['price'];
}
// Update product prices
if (isset($new_product_price)) {
$_price = array (
'price' => abs($new_product_price),
'lower_limit' => 1,
);
if (!isset($_product_data['prices'])) {
$_product_data['prices'][0] = $_price;
} else {
unset($_product_data['prices'][0]);
array_unshift($_product_data['prices'], $_price);
}
}
if (!empty($_product_data['prices'])) {
if (PRODUCT_TYPE == 'ULTIMATE' && $company_id) {
$table_name = '?:ult_product_prices';
$condition = db_quote(' AND company_id = ?i', $company_id);
} else {
$table_name = '?:product_prices';
$condition = '';
}
db_query("DELETE FROM $table_name WHERE product_id = ?i $condition", $product_id);
foreach ($_product_data['prices'] as $v) {
$v['type'] = !empty($v['type']) ? $v['type'] : 'A';
$v['usergroup_id'] = !empty($v['usergroup_id']) ? $v['usergroup_id'] : 0;
if ($v['lower_limit'] == 1 && $v['type'] == 'P' && $v['usergroup_id'] == 0) {
fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('cant_save_percentage_price'));
continue;
}
if (!empty($v['lower_limit'])) {
$v['product_id'] = $product_id;
if (!empty($company_id)) {
$v['company_id'] = $company_id;
}
if ($v['type'] == 'P') {
$v['percentage_discount'] = ($v['price'] > 100) ? 100 : $v['price'];
$v['price'] = $new_product_price;
}
unset($v['type']);
db_query("REPLACE INTO $table_name ?e", $v);
}
}
}
return $_product_data;
}




in skins/basic/admin/views/products/update.tpl write somewhere this part of code:




```php


{$lang.price} {$lang.currency}:

{foreach from=$currencies item="currency_code"}
{$currency_code.currency_code}
{/foreach}


```