| Author |
Message |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Jan 10, 2009 11:34 am |
|
Gotcha,
I want to show estimated prices for different currencies. It is not a hard function to write when you know exactly what currencies you working with, but prolly difficult if you don't.
Anyway, I doubt I can deploy such a function without you. Any thoughts? Maybe I could write the function and stick it in the index.php? Oh, I feel a headache coming  |
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sat Jan 10, 2009 12:30 pm |
|
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Jan 10, 2009 12:32 pm |
|
Yeah, I think I can make that work. Just need to put some thought into it. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Jan 10, 2009 2:09 pm |
|
I know you can pass one value, but can you pass two?
| Code: |
{conversion currency_symbol=$currency_symbol item_cost=$item.item_cost} |
I might have to pass item_id and then grab all the other info. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Jan 10, 2009 2:21 pm |
|
I changed it to just pass one variable from the .tpl. After clearing templates_c I get,
| Code: |
[01-10-09 01:20:22 pm][256](Line:1095) Smarty error: [in default/shop/main.tpl line 89]: syntax error: unrecognized tag 'conversion' (Smarty_Compiler.class.php, line 590) [/home/ped99/public_html/includes/smarty/libs/Smarty.class.php] |
I feel like I am forgetting a step.
| Code: |
{conversion item_id=$item.item_id} |
function.conversion.php (rough draft anyway)
| Code: |
function smarty_function_conversion($params, &$smarty){
require("mainfile.php");
global $db;
$item_id = intval($params['item_id']);
$sql = "SELECT item_cost, item_currency_symbol FROM shop_items WHERE item_id = '".$item_id."'";
$query = $db->sql_query($sql);
$row = $db->sql_fetchrow($query);
$item_cost = $row['item_cost'];
$currency_symbol = $row['item_currency_symbol'];
if($currency_symbol == '£'){
$converted = '$'.$item_cost * 2;
}elseif($currency_symbol == '$'){
$converted = '£'.$item_cost / 2;
}
$conversion = '('.$currency_symbol.$item_cost.') ('.$converted.')';
return $conversion; |
|
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sat Jan 10, 2009 7:05 pm |
|
You are making it harder then it needs to be, also, if the item is discounted, the price will be way off. No need for mainfile, or any db queries in this function either. I would also pull the current exchange rate from somewhere instead of assuming 2 to 1.
In the template:
| Code: |
$item.item_currency_symbol {conversion item_cost=$item.item_cost item_currency=$item.item_currency} |
in function.conversion.php
| php: |
// make sure this file is in the tpl_plugins folder
function smarty_function_conversion($params, &$smarty){
if($params['item_currency'] == 'USD') {
// do conversion
} elseif ($params['item_currency'] == 'GBP') {
// do conversion
}
return $converted_currency;
}
|
|
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Jan 10, 2009 7:10 pm |
|
My first function looked very similar to that, but as far as getting exchange rates. It much harder to find some place that keeps them updated for free.
I did notice the problem with the special discount, that one is gonna be tricky if not impossible.
I will keep playing with it soon as I finish working on www.clan-themes.co.uk/search.php
btw, I always make it harder than it needs to be jeez.. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Jan 10, 2009 7:26 pm |
|
What is this usually caused by
| Code: |
[01-10-09 06:25:48 pm][256](Line:1095) Smarty error: [in default/shop/main.tpl line 89]: syntax error: unrecognized tag 'conversion' (Smarty_Compiler.class.php, line 590) [/home/ped99/public_html/includes/smarty/libs/Smarty.class.php] |
My function is in the plugins folder. |
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sat Jan 10, 2009 7:43 pm |
|
It basically isn't finding that function so and that could be for many reasons. File permissions, spelling, wrong folder, wrong filename or function name format, etc. |
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Mon Jan 12, 2009 9:24 am |
|
Did you ever figure it out floppy? |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Mon Jan 12, 2009 10:46 am |
|
Didn't really play with it anymore yesterday. I changed the variable name to make sure it wasn't a conflict with another plugin.
Like you said, it is treating it as if it can't be found. However, my gturl (well your) function is working fine. I think CT is still running on 2.07 if that would make any difference. |
| |
|
|
 |
Guardian

Joined: Dec 09, 2006
Posts: 335
|
Posted:
Wed Jan 14, 2009 5:16 am |
|
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Tue Jan 20, 2009 5:41 pm |
|
Thanks Guardian, the current problem is it doesn't recognize any file as a plugin. I am not sure why yet. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Tue Jan 20, 2009 6:45 pm |
|
I am an idiot. Gotcha gave me the answer and I just didn't realize it. "tpl_plugins". I had my mind set that it was still plugins cause all the old files were still there. I think I thought that was a 2.08 change.
Ok, on with the mod. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Tue Jan 20, 2009 9:18 pm |
|
|
|
 |
|
|